大家好,我是考100分的小小码 ,祝大家学习进步,加薪顺利呀。今天说一说oracle处理重复数据「终于解决」,希望您对编程的造诣更进一步.
person表中有id和name两个字段,id是唯一值,若id相同,则认为记录重复。
-
- 查找重复id
select id from person group by id having count(*)>1
-
- 查找重复数据
select * from person where id in (select id from person group by id having count(*)>1)
-
- 删除重复记录,保留rowid最小的记录
delete from person where id in (select id from person group by id having count(id)>1) and rowid not in (select min(rowid) from person group by id having count(*)>1)
-
- 查询表中重复记录(多个字段)
select * from tablename a where (a.seq,a.id) in (select seq,id from tablename group by sql,id having count(*)>1)
-
- 删除表中重复记录(多个字段),只保留rowid最小的字段
delete from tablename a where (a.id,a.seq) in (select id,sql from tablename group by id,sql having count(*)>1) and rowid not in (select min(rowid) from tablename group by id,sql having count(*)>1)
-
- 查找表中重复数据,不包含rowid最小记录
select * from tablename a where (a.id,a.seq) in (select id,seq from tablename group by id,seq having count(*)>1) and rowid not in (select min(rowid) from tablename group by id,seq having count(*)>1)
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/13125.html