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)