我要统计一个表中最近10条记录中 字段aa=2出现的次数我现在用select * from table where aa=2 order by id desc limit 10
返回的是所有数据中aa=2的前10条记录,不是我想要的结果。求注应该怎么写啊

解决方案 »

  1.   

    select aa, count(*) as aaNum from(select * from table where aa=2 order by id desc limit 0,10) where 1 
    这样就可以实现了,楼主试试。我已经试验过了。
      

  2.   

    select aa,count(*) from (select * from table   order by id desc limit 0,10 ) as t where aa =2 group by aa
      

  3.   

    hehe ,刚看到,两种写法是一样的,只不过,yangxiao_jiang  的写法,执行效率要慢一些(数据量大的时候,执行时间会长一些)。