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


    1、查找表中多余的重复记录,重复记录是根据单个字段(Id)来判断
     
    select * from 表 where Id in (select Id from 表 group byId having count(Id) > 1)
     
    2、删除表中多余的重复记录,重复记录是根据单个字段(Id)来判断,只留有rowid最小的记录
     
    DELETE from 表 WHERE (id) IN ( SELECT id FROM 表 GROUP BY id HAVING COUNT(id) > 1) AND ROWID NOT IN (SELECT MIN(ROWID) FROM 表 GROUP BY id HAVING COUNT(*) > 1);
     
    3、查找表中多余的重复记录(多个字段)
     
    select * from 表 a where (a.Id,a.seq) in(select Id,seq from 表 group by Id,seq having count(*) > 1)
     
    4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录
     
    delete from 表 a where (a.Id,a.seq) in (select Id,seq from 表 group by Id,seq having count(*) > 1) and rowid not in (select min(rowid) from 表 group by Id,seq having count(*)>1)
     
    5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录
     
    select * from 表 a where (a.Id,a.seq) in (select Id,seq from 表 group by Id,seq having count(*) > 1) and rowid not in (select min(rowid) from 表 group by Id,seq having count(*)>1)
      
    上述转载自:http://www.cnblogs.com/252e/archive/2012/09/13/2682817.html
     
     
      实际项目遇见千万级别的数据时,删除重复的数据并不适用(在oracle上800多万条数据用伤处方法去重复N个小时没有结果)。
      下面给出在大数据情况下的去重复操作:
    1. 建临时表:CREATE TABLE  tt as select a.name, MAX(a.ROWID) dataid from tablenamea GROUP BY a.name;  或 CREATE TABLE tt AS (select distinct * from tablename);
    2. 清空原表数据:truncatetable tablename;
    3. 将临时表数据填充到原表中:insert into tablename (select * from tt); --千万级别数据2分钟左右完成
    4. 删除临时表:drop table tt;
    5. 提交:commit
     
     
     
     
     
  • 相关阅读:
    iptables 端口转发规则
    iptables 设置端口转发/映射
    iptables 从一台机到另一台机端口转发
    iptables nat 技术转发
    统计将⽂文件内容读出,然后统计读出的字符串串中每个字符的个数
    day03-课堂笔记-大纲
    day03-课堂笔记
    转载:linux同步时间信息
    获取列表的索引操作:enumerate
    oldboy-作业01.登录多次进行账号锁定
  • 原文地址:https://www.cnblogs.com/xx0405/p/5319987.html
Copyright © 2020-2023  润新知