mysql--记2次脏数据清理
作者:互联网
有时候程序执行的过程中,可能有逻辑漏洞,导致同样一条数据多次insert到表里,造成了垃圾数据,在清理的时候又不能一杆子都打死,需要将重复数据中,id最小的保留
DELETE FROM public_sentiment WHERE id IN ( SELECT * FROM ( SELECT id FROM public_sentiment WHERE (sentiment_id,vuln_name) IN ( SELECT sentiment_id,vuln_name FROM public_sentiment GROUP BY sentiment_id,vuln_name HAVING COUNT(1) > 1 ) AND id NOT IN ( SELECT MIN(id) FROM public_sentiment GROUP BY sentiment_id,vuln_name HAVING COUNT(1) > 1 ) ) AS repeat_copy );
DELETE FROM 表名 WHERE id IN ( SELECT * FROM ( SELECT id FROM 表名 WHERE (字段名1) IN ( SELECT 字段名1 FROM 表名 GROUP BY 字段名1 HAVING COUNT(1) > 1 ) AND id NOT IN ( SELECT MIN(id) FROM 表名 GROUP BY 字段名1 HAVING COUNT(1) > 1 ) ) AS repeat_copy );
标签:COUNT,GROUP,sentiment,--,表名,次脏,mysql,id,SELECT 来源: https://www.cnblogs.com/lutt/p/16301065.html