oracle 查询重复数据以及删除重复数据
2015-07-27 15:14
633 查看
<span style="font-family:Courier New;font-size:18px;">select a.facilityid, a.faulttime, a.domainid, a.facilitytype1, a.facilitytype2, a.facilitytype3, count(*) from ips_fault_facility a group by a.facilityid, a.faulttime, a.domainid, a.facilitytype1, a.facilitytype2, a.facilitytype3 having count(*) > 1</span>
<span style="font-family:Courier New;font-size:18px;">create table ips_fault_facility1 as select * from ips_fault_facility a where rowid <> (select min(rowid) from ips_fault_facility b where a.facilityid = b.facilityid and a.faulttime = b.faulttime and a.domainid = b.domainid and a.facilitytype1 = b.facilitytype1 and a.status = b.status and a.facilitytype2 = b.facilitytype2 and a.facilitytype3 = b.facilitytype3)</span>
--删除重复数据
<span style="font-family:Courier New;font-size:18px;">delete from ips_fault_facility a where exists(select 1 from ips_fault_facility1 b where a.uuid = b.uuid)</span>
Oracle
删除重复数据只留一条
查询及删除重复记录的SQL语句1、查找表中多余的重复记录,重复记录是根据单个字段(Id)来判断
select * from 表 where Id in (select Id from 表 group byId having count(Id) > 1)
2、删除表中多余的重复记录,重复记录是根据单个字段(Id)来判断,只留有rowid最小的记录
DELETE from 表 WHERE (id) IN ( SELECT id FROM 表 GROUP BY id HAVING COUNT(id) > 1) AND ROWID NOT IN (SELECT MIN(ROWID) FROM 表 GROUP BY id HAVING COUNT(*) > 1);
3、查找表中多余的重复记录(多个字段)
select * from 表 a where (a.Id,a.seq) in(select Id,seq from 表 group by Id,seq having count(*) > 1)
4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录
delete from 表 a where (a.Id,a.seq) in (select Id,seq from 表 group by Id,seq having count(*) > 1) and rowid not in (select min(rowid) from 表 group by Id,seq having count(*)>1)
5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录
select * from 表 a where (a.Id,a.seq) in (select Id,seq from 表 group by Id,seq having count(*) > 1) and rowid not in (select min(rowid) from 表 group by Id,seq having count(*)>1)
相关文章推荐
- Android之获取手机上的图片和视频缩略图thumbnails
- 基于 Red Hat 的发行版 Oracle Linux 正式发布Oracle Linux 7.1
- 数据库链接字符串查询网站
- Oracle Containers for J2EE远程安全漏洞(CVE-2014-0413)
- Oracle 10g R2不能使用EM的问题
- 表空间操作
- PreparedStatement中in子句的处理
- VMware下RedHat4.8_64位安装Oracle 10g RAC--简略脚本
- oracle sql日期比较
- 基于 Red Hat 的发行版 Oracle Linux 正式发布Oracle Linux 7.1
- DB2实例管理
- DB2实例管理
- OS block size和Oracle block size,查找OS Blocksize的方法
- 保障MySQL数据安全的14个最佳方法
- mysql问答汇集
- oracle中创建数据库和表空间的几点总结
- 数据库自动备份脚本
- 创建一个空的IBM DB2 ECO数据库的方法