sql查找两条以上的数据 having

来源:互联网 发布:mac下载游戏的网站 编辑:程序博客网 时间:2024/06/06 08:10
主要是查询数据库中两条或者多条相同ID对应不同的人,或者说多个人对应一个ID,要的做的是查询哪些ID是对应2个人以上的。 

select *
  from formlsbenefi
 where prtnum in (select prtnum
                    from formlsbenefi t
                   group by prtnum
                  having count(1) > 1); 
参考:
select f1,f2,...,fn
from table
group by f1,f2,...,fn
having count(1)>1 查出存在相同的f1,f2,..,fn
想查找出记录则
select t1.* from table t1
join (select f1,f2,...,fn from table group by f1,f2,...,fn having count(1)>1) t2
on t1.f1=t2.f1 and t1.f2=t2.f2 and ... and t1.fn=t2.fn

0 0
原创粉丝点击