如何用SQL进行统计表里面一个字段最多出现3次的所有数据。
例如:统计下面id字段不能重复超过三条的所有条数
id name
1 a
1 b
1 c
2 aa
2 bb
1 dd
3 ccc
select id,name from test group by id having count(*)<=3
select id,count(1)条数 from test group by id
having count(1) <3
select id,name from table_name where count(1)<=3 group by id;
以上的答案我不做评论,我给你来个sql吧
select * from table a exists (select b.id,count(1) from table b where a.id = b.id group by b.id having count(1) <= 3)