select a,count(b) from table where b=1 group by a; -----------------------------------------------------------------假设是要统计b=1的次数,同时c唯一的次数,按a分组可以用下面的语句:select t.a,count(t.b) from (select * from table where b=1 group by c) t group by t.a;