sql查所有数据要求相同列值相等个数大于三的

来源:百度知道 编辑:UC知道 时间:2024/06/05 16:50:08
例如a表有id name 两列 查所有数据,条件是id相同的个数大于3

select *
from tablename
where id in
(
select id
from tablename
group by id
having count(*) > 3
);

select count(*) num,id
from table group by id
having num >3

select id,count(id) sl into #b from a
group by id
having count(id)>3

select A.id,A.name from a A,#B B
WHERE A.id=B.id
group by A.id,A.name

考虑到id相同时name可能不同

select * from 表名
where id in (select id from 表名 group by id having count(*)>3)

楼上说的都不对,应该这样:

select id,name from a where id in (select id from a group by a having count(*)>3)