oracle查询表中多余的重复记录(多个字段)

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

     --查询重复数据
       select *
         from app_jf_value t1
        where (t1.jfindcode, t1.areacode, t1.kpitype, t1.created_at) in
              (select jfindcode, areacode, kpitype, created_at
                 from app_jf_value
                group by jfindcode, areacode, kpitype, created_at
               having count(*) > 1);
               
       --删除重复数据
       delete from app_jf_value t1
        where (t1.jfindcode, t1.areacode, t1.kpitype, t1.created_at) in
              (select jfindcode, areacode, kpitype, created_at
                 from app_jf_value
                group by jfindcode, areacode, kpitype, created_at
               having count(*) > 1)
          and rowid not in
              (select min(rowid)
                 from app_jf_value
                group by jfindcode, areacode, kpitype, created_at
               having count(*) > 1);


转载于:https://my.oschina.net/Cheney521/blog/386865

你可能感兴趣的:(oracle查询表中多余的重复记录(多个字段))