DELETE
FROM
pet_order
WHERE
name IN (
SELECT
t.name
FROM
(
SELECT
name
FROM
pet_order
GROUP BY
name
HAVING
count(1) > 1
) t
)
AND id NOT IN (
SELECT
dt.mindeptno
FROM
(
SELECT
min(id) AS mindeptno
FROM
pet_order
GROUP BY
name
HAVING
count(1) > 1
) dt
)
DELETE from TableName WHERE (name) in
(SELECT name from (SELECT name FROM TableName GROUP BY name HAVING COUNT(*)>1) s1)
AND
id NOT in (SELECT id from (SELECT id FROM TableName GROUP BY name HAVING COUNT(*)>1) s2);
#把TableName换成你的表名,name换成你要去重的字段
第一个SQL执行时间
受影响的行: 6
时间: 0.008s
第二个SQL执行时间
受影响的行: 6
时间: 0.006s
本文为Pasa吴原创文章,转载无需和我联系,但请注明来自Pasa吴博客https://www.pasawu.top
最新评论