zoukankan      html  css  js  c++  java
  • Oracle 删除重复记录

    1、查找表中多余的重复记录
    select * from 表 a where (a.Id,a.seq) in(select Id,seq fromgroup by Id,seq having count(*) > 1)   --a.Id+a.seq唯一
    select *
         from bi_network_znf a
        where (a.eqp_ip, a.create_time) in
              (select aa.eqp_ip, aa.create_time
                 from bi_network_znf aa
                group by aa.eqp_ip, aa.create_time
               having count(1) > 1)
        order by a.eqp_ip;
     
    2、删除表中多余的重复记录,只留有rowid最小的记录
    delete from 表 a where (a.Id,a.seq) in (select Id,seq fromgroup by Id,seq having count(*) > 1) and rowid not in (select min(rowid) fromgroup by Id,seq having count(*)>1)
     select *
        /*delete*/ from bi_network_znf a
        where (a.eqp_ip, a.create_time) in
              (select aa.eqp_ip, aa.create_time
                 from bi_network_znf aa
                group by aa.eqp_ip, aa.create_time
               having count(1) > 1)
         and a.rowid not in (select min(rowid)
                 from bi_network_znf aa
                group by aa.eqp_ip, aa.create_time
               having count(1) > 1)
       order by a.eqp_ip --删除时需要注释掉
       ;
        commit;
  • 相关阅读:
    Scoket简介
    AOP
    Windows服务
    Nginx 教程 (1):基本概念
    异步编程
    并发编程
    常用排序
    序列化
    MSBuild/Projectjson
    不汇报是职场发展的绊脚石
  • 原文地址:https://www.cnblogs.com/weimengjiacan/p/9406343.html
Copyright © 2011-2022 走看看