码迷,mamicode.com
首页 > 数据库 > 详细

oracle查询重复数据

时间:2017-06-29 13:37:22      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:acl   row   查询   数据   bsp   org   字段   重复数   重复   

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查询重复数据

标签:acl   row   查询   数据   bsp   org   字段   重复数   重复   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!