MYSQL_实用 SQL_删除重复数据

DELETE
FROM
	pub_goods
WHERE
	goodsno IN (
		SELECT
			*
		FROM
			(
				SELECT
					goodsno
				FROM
					pub_goods
				GROUP BY
					goodsno
				HAVING
					COUNT(goodsno) > 1
			) t1
	)
AND mgoodsid NOT IN (
	SELECT
		*
	FROM
		(
			SELECT
				MIN(mgoodsid)
			FROM
				pub_goods
			GROUP BY
				goodsno
			HAVING
				COUNT(goodsno) > 1
		) t2
)

posted on 2019-06-04 17:33  野区杰西  阅读(185)  评论(0编辑  收藏  举报

导航