• mysql重复记录的查询删除方法


    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 C_Yyt
    WHERE (Elon IN   (SELECT elon   FROM C_Yyt   GROUP BY elon, wd   HAVING COUNT(*) > 1)) AND (wd IN    (SELECT wd    FROM C_Yyt       GROUP BY elon, wd   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)

    6、删除重复数据

    1、将重复数据中的最小的id都找出来,并插入到一个临时表中;
    2、再通过表关联删除掉重复的数据;
    INSERT into line_pass_init select min(id) from tt_rps_line_passzone_info_init group by plan_send_batch_dt,line_id,passid,order_flag having count(*)>1
    #性能低
    DELETE from tt_rps_line_passzone_info_init where id not exists (select id from line_pass_init);
    #性能高
    delete from tt_rps_line_passzone_info_init a where not exists(select 1 from line_pass_stor_init b where a.id=b.id);

  • 相关阅读:
    四瓶化学试剂合成了人工生命
    DNA 就是软件代码
    首例人造生命,碱基对达到100多万个
    看到一个新闻管理系统,看上去开源,其实是骗你使用
    日本可合成碱基对 遗传信息"无中生有"
    新生命如何在实验室“被创造”
    一个基因有多少碱基对
    A、T、G、C四个字母(构成碱基的基本单位)的不同排列,画出一张基因图谱
    远程图片下载不能显示的问题
    30亿个碱基对组成,分布在细胞核的23对染色体中
  • 原文地址:https://www.cnblogs.com/duanxz/p/6165323.html
Copyright © 2020-2023  润新知