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,记得多执行几次

  • 相关阅读:
    Scrapy中间件
    Scrapy简介
    Scrapy解析器xpath
    postman
    yarn
    brew 安装 yarn 时候失败
    immutability-helper 用途+使用方法
    js 正则
    react redux 应用链接
    react 事件传参数
  • 原文地址:https://www.cnblogs.com/gqymy/p/10026735.html
Copyright © 2011-2022 走看看