【Oracle |
您所在的位置:网站首页 › oracle数据库对查出的数据去重命令 › 【Oracle |
oracle查找/删除重复的数据(单个字段和多个字段条件)
单个字段: --查找重复的全部数据(单个字段) 思路: 1.根据字段tid分组,数量大于1的表示tid字段有重复的数据; 2.根据1查询出来的tid数据为条件,再查询全部重复的数据。 SQL: select t.* from test1108 t where t.tid in ( select tid from test1108 group by tid having count(tid) > 1);--删除多余的重复数据(单个字段),重复的数据保留rowid最小的行 思路: 1.根据字段tid分组,数量大于1的表示有重复数据; 2.因表中每行都有一个伪列rowid,查找出重复数据中最小的rowid; 3.根据1、2的并行条件重复的数据,但保留重复数据中rowid最小的值。 SQL: delete from test1108 t where t.tid in ( select tid from test1108 group by tid having count(tid) > 1) and rowid not in ( select min(rowid) from test1108 group by tid having count(tid) >1);多个字段: --查找重复的全部数据(多个字段) 思路: 1.根据字段tid,tname分组,数量大于1的表示字段tid,tname有重复的数据; 2.根据1查询出来的tid,tname数据为条件,再查询全部重复的数据。 SQL: select * from test112101 t where (t.tid,t.tname) in ( select tid,tname from test112101 t1 group by t1.tid,t1.tname having count(*) >1 );--删除多余的重复数据(多个字段),重复的数据保留rowid最小的行 思路: 1.根据字段tid,tname分组,数量大于1的表示有重复数据; 2.因表中每行都有一个伪列rowid,查找出重复数据中最小的rowid; 3.根据1、2的并行条件重复的数据,但保留重复数据中rowid最小的值。 SQL: delete from test112101 t where (t.tid,t.tname) in ( select tid,tname from test112101 t1 group by t1.tid,t1.tname having count(*) >1 ) and rowid not in( select min(rowid) from test112101 group by tid,tname having count(1)> 1);
|
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |