首页 > 数据库技术 > 详细

oracle查询重复数据

时间:2017-06-29 13:17:14      阅读:358      评论:0      收藏:0      [点我收藏+]

oracle查询重复数据
select * from 表 where 条件 and 判重字段 not in
(select 判重字段 from 表 where 条件 group by 判重字段 having count(*) > 1)

根据rowid删除重复数据,保留一条
delete from 表 where 条件 and 判重字段 not in
(select 判重字段 from 表 where 条件 group by 判重字段 having count(*) >1)
and rowid not in
(select max(rowid) from 表 where 条件 group by 判重字段 having count(*) >1)

eg:删除导入病案数据中的重复数据
delete from rhsa_hs4_1_2013_temp
where period = ‘00083‘
and org_id = ‘370000003584‘
and (bah, zycs) in (select bah, zycs
from rhsa_hs4_1_2013_temp
where period = ‘00083‘
and org_id = ‘370000003584‘
group by bah, zycs
having count(*) > 1)
and rowid not in (select max(rowid)
from rhsa_hs4_1_2013_temp
where period = ‘00083‘
and org_id = ‘370000003584‘
group by bah, zycs
having count(*) > 1)

 

oracle查询重复数据

原文:http://www.cnblogs.com/liutie/p/7093869.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!