查询数据库表中同一字段值相同的数据行 +exists 的使用


--方法一、
select * from ZW_YHZDXX_30 a where ((select count(1) from zw_yhzdxx_30 b where b.yhbh = a.yhbh) > 1);
--方法二、
select * from ZW_YHZDXX_30 a where exists
(select 1 from ZW_YHZDXX_30 b where a.yhbh=b.yhbh and a.rowid<>b.rowid );
 --方法三、
--此句耗费最小,效率最高
select * from ZW_YHZDXX_30 where yhbh in (select yhbh from ZW_YHZDXX_30 group by yhbh having count(*)>1)


select * from gs_in_money_receipt a where exists
(select 1 from gs_in_money_receipt b where a.fp_id=b.fp_id and a.id<>b.id )

你可能感兴趣的:(查询数据库表中同一字段值相同的数据行 +exists 的使用)