delete from TableName where id in
(

SELECT ID FROM
(
SELECT *
FROM
TableName t0
WHERE
(t0.Field1,t0.Field2)
IN (
SELECT
t1.Field1,
t1.Field2
FROM
TableName AS t1
GROUP BY
t1.Field1,
t1.Field2
HAVING
count(*) > 1
)
AND t0.ID NOT IN (
SELECT
min(t2.ID)
FROM
TableName as t2
GROUP BY
t2.Field1,
t2.Field2
HAVING
count(*) > 1
)

) AS tt1

);

posted on 2017-08-10 16:51  邢帅杰  阅读(471)  评论(0编辑  收藏  举报