欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

sql查询重复数据

程序员文章站 2024-01-16 16:19:47
select * from t_contract_purchase t where t.purcontractid in (select purcontractid from...
select * from t_contract_purchase t where t.purcontractid  in (select purcontractid from t_contract_purchase
  group by purcontractid having count(1)>1) and t.subcompanyid='****' order by t.purcontractid desc, t.purcharseid desc;

查询表t_contract_purchase中,所有purcontractid字段内容重复的数据,并把数据按照先按照purcontractid,再按照purcharseid 降序排列展示出来。

更加精简一点,可以将语句改成:

select * from t_contract_purchase t where (select count(*) from t_contract_purchase s where s.purcontractid=t.purcontractid)>1