zoukankan      html  css  js  c++  java
  • mysql对表中数据根据某一字段去重

    要删除重复的记录,就要先查出重复的记录,这个很容易做到

    select * from 表名 group by 根据哪一个字段(简称字段) having count(字段) > 1

    注意:这是查出所有重复记录的第一条记录,需要保留,因此需要添加查询条件,查出所有的重复记录

    select id,expect from cqssc where expect in (select expect from cqssc group by expect having count(expect)>1) 
    
    and id not in(select min(id) from cqssc group by expect having count(expect)>1)

    然后

    delete from cqssc where id in (select id from (select id from cqssc where expect in 
    
    (select expect from cqssc group by expect having count(expect)>1) and id not in
    
    (select min(id) from cqssc group by expect having count(expect)>1)) as tmpresult)

    删除成功,最后再查询一下看是否还有重复记录

  • 相关阅读:
    linux系统cpu和内存占用率
    虚拟机网卡设置
    C语言中打印返回值
    MQTT_DEMO
    MQTT-C-UDP_PUB
    MQTT-C-PUB
    结构体指针用法
    linux系统如何操作隐藏文件
    mqtt学习笔记
    XML文件的读取----cElementTree
  • 原文地址:https://www.cnblogs.com/wxy0126/p/11137529.html
Copyright © 2011-2022 走看看