时间:2021-07-01 10:21:17 帮助过:2人阅读
-- 方案一 ;DELETE FROM TabTest WHERE id NOT IN ( SELECT * FROM ( SELECT id FROM TabTest GROUP BY factorA, factorB, factorC ) b );
-- 方案二 DELETE FROM TabTest WHERE id IN ( -- MySQL Error 1093 – Can‘t specify target table for update in FROM clause SELECT b.id FROM ( SELECT tOuter.`id` FROM TabTest tOuter INNER JOIN ( SELECT tInner.id, tInner.factorA, tInner.factorB, tInner.factorC FROM TabTest tInner GROUP BY tInner.factorA, tInner.factorB, tInner.factorC HAVING COUNT(1) > 1 ) a ON tOuter.`factorA` = a.`factorA` AND tOuter.`factorB` = a.`factorB` AND tOuter.`factorC` = a.`factorC` WHERE tOuter.`id` <> a.`id` )b )
方案一: 数据量小时, 比较便捷
方案二: 数据量大时使用, 第一个方案在70万数据下试过, 5分钟出不来结果, 放弃, 使用第二种方案, 秒完.
删除特定影响因素(字段列)下的重复记录(MySQL)
标签: