• 【Oracle】【11】删除重复数据只留一条


    正文:

    1,根据单个字段(id)查找表中是否有重复记录
    select * from table t where t.id in (select t.id from table t group by t.id having count(t.id) > 1);
    
    select * from (select t.id, count(1) count from table t group by t.id) t where t.count != 1;
     
    2,根据单个字段(id),删除重复的数据,只留下rowid最小的记录
    delete from table t 
    where t.id in( select t.id from table t group by t.id having count(t.id) > 1) 
    and rowid not in (select min(rowid ) from table t group by t.id having count(t.id) > 1);
     
    3,根据多个字段(id, name)查找表中是否有重复记录
    select * from table t where (t.id, t.name) in (select t.id, t.name from table t group by t.id, t.name having count(1) > 1)
     
    4,根据多个字段(id, name),删除重复的数据,只留下rowid最小的记录
    delete from table t 
    where (t.id, t.name) in( select t.id, t.name from table t group by t.id, t.name having count(1) > 1) 
    and rowid not in (select min(rowid) from table t group by t.id, t.name having count(1) > 1);
     

    参考博客:

    Oracle 删除重复数据只留一条 - 张曾人 - 博客园
    http://www.cnblogs.com/252e/archive/2012/09/13/2682817.html

  • 相关阅读:
    并列显示
    vertical-align,text-align 和 align的区别
    实现水平垂直居中
    overflow属性
    float属性
    table 标签
    idea中修改默认maven
    使用host的方式来破解idea
    mysql分区
    mysql数据库设计规范
  • 原文地址:https://www.cnblogs.com/huashengweilong/p/10810662.html
Copyright © 2020-2023  润新知