ORACLE删除重复数据只留一条 |
您所在的位置:网站首页 › oracle重复记录的最后10条 › ORACLE删除重复数据只留一条 |
数据库操作中,经常会因为导数据造成数据重复,需要进行数据清理,去掉冗余的数据,只保留正确的数据 1、查找表中多余的重复记录,重复记录是根据单个字段(Id)来判断 代码语言:javascript复制select * from 表 where Id in (select Id from 表 group byId having count(Id) > 1)2、删除表中多余的重复记录,重复记录是根据单个字段(Id)来判断,只留有rowid最小的记录 代码语言:javascript复制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、查找表中多余的重复记录(多个字段) 代码语言:javascript复制select * from 表 a where (a.Id,a.seq) in(select Id,seq from 表 group by Id,seq having count(*) > 1)4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录 代码语言:javascript复制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最小的记录 代码语言:javascript复制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) |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |