sql语句,分组时查询字段等于值的记录个数

2024-12-01 18:22:17
推荐回答(1个)
回答1:

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;