描述
在日常开发中遇到的问题,历史数据中存在重复数据需要删除,但是仍需要保留一条。
处理
DELETE FROM 表名 WHERE (字段1,字段2)
IN
(SELECT 字段1,字段2 FROM (SELECT 字段1,字段2 FROM 表名 GROUP BY 字段1,字段2 HAVING COUNT(*)>1) t1)
AND
id NOT IN (SELECT MIN(id) FROM (SELECT id FROM 表名 GROUP BY 字段1,字段2 HAVING COUNT(*)>1) t2);
查找的资料
https://www.cnblogs.com/XiaoMingBlingBling/p/11146375.html