sql 从SQL表中删除重复项

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 从SQL表中删除重复项相关的知识,希望对你有一定的参考价值。

WITH cct
AS (SELECT
		a.RowHash,
		RANK() OVER (PARTITION BY a.RowHash ORDER BY a.ID) AS rkk,
		a.id
	FROM sym.dimAccounts a
	WHERE a.RowHash IN (SELECT
			a.RowHash
		FROM sym.dimAccounts a
		GROUP BY a.RowHash
		HAVING (COUNT(a.RowHash) > 1)))
delete
FROM sym.dimAccounts
WHERE ID IN (SELECT
		cct.id
	FROM cct WHERE cct.rkk > 1)
WITH cct AS (SELECT mmtt.TRANSACTION_ID, RANK() OVER(PARTITION BY mmtt.TRANSACTION_ID ORDER BY mmtt.ID) AS rkk, mmtt.ID FROM MTL_MATERIAL_TRANSACTIONS_Test mmtt
WHERE mmtt.TRANSACTION_ID in (SELECT     mmtt.TRANSACTION_ID
FROM         MTL_MATERIAL_TRANSACTIONS_Test mmtt
GROUP BY mmtt.TRANSACTION_ID
HAVING     (COUNT(mmtt.TRANSACTION_ID) > 1))
)
DELETE FROM MTL_MATERIAL_TRANSACTIONS_Test WHERE ID IN (select cct.ID FROM cct)

以上是关于sql 从SQL表中删除重复项的主要内容,如果未能解决你的问题,请参考以下文章

如何在从多个表中获取多行的同时删除 sql JOIN 中的重复项

sql 从表中删除重复项。

如何从表中删除重复值 [重复]

如何根据某个字段从数据库表中删除重复项

用SQL语句,删除掉重复项只保留一条

从 DB2 中的表中删除重复项