zoukankan      html  css  js  c++  java
  • mysql删除重复数据

    先查询某字段重复的全部数据

    select count(param) as count from table group by param having count > 1

    (多个字段判断重复数据)

    select count(param) as count1, count(param2) count2 from table group by param, param2 having count > 1 and count2 > 1

    因为删除重复数据时肯定会保留一条,所以使用not in(not exists) 在重复数据中保留一条数据

    select min(id) as id ,count(param) as count from table group by param having count > 1   //根据最大或最小值来进行数据保留

    select count(param) as count from table where id not in (

    select t.id from ( select min(id) as id ,count(param) as count from table group by param having count > 1  ) t

    ) group by param having count > 1

    查询的sql已经写好,接下来就直接做删除操作

    delete from table where id in 上面的sql

    每次删除一个重复id,记得多执行几次

  • 相关阅读:
    sss
    stm32cube使用
    FreeRTOS
    嵌入式网站
    CRC分段校验
    IAR编译器
    (转)UCOSII源代码剖析
    (转)stm32硬件IIC
    keil MDK注意事项
    (转).Net中自定义类作为Dictionary的key详解
  • 原文地址:https://www.cnblogs.com/gqymy/p/10026735.html
Copyright © 2011-2022 走看看