zoukankan      html  css  js  c++  java
  • oracle删除同一张表的重复记录

    1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断
    select * from people
    where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)

    2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录
    delete from people 
    where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)
    and rowid not in (select min(rowid) from people group by peopleId having count(peopleId )>1)

    3、查找表中多余的重复记录(多个字段) 
    select * from vitae a
    where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)

    4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录
    delete from vitae a
    where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
    and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)

    5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录
    select * from vitae a
    where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
    and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)


    关键看什么字段相同算重复,如果是arrearmain_id、reladdr、addrsourcetype的话,那这样写是最高效的,因为用了rowid:
    delete from cncc_customeraddr_tab t
     where t.rowid > (select min(x.rowid)
      from cncc_customeraddr_tab x
      where x.arrearmain_id = t.arrearmain_id
      and x.reladdr = t.reladdr
      and x.addrsourcetype = t.addrsourcetype)
      and t.addrsourcetype = '1300000001'

  • 相关阅读:
    Framework 7 日历插件改成Picker 模式
    DataTables 表格固定栏使用方法
    DIV内滚动条滚动到指定位置
    js类型转换 之 转字符串及布尔类型
    js类型转换 之 转数字类型
    UrlRewriter.dll伪静态实现二级域名泛解析
    sql server2005内存过高释放方法
    HttpContext.Current.RewritePath方法重写URL
    sql2005数据库转换成sql2000
    asp.net获取当前页面源码并生成静态页面
  • 原文地址:https://www.cnblogs.com/wjlstation/p/2555832.html
Copyright © 2011-2022 走看看