目标是找到重复项。
Select Column1, Column2, Column3
from Tablename
where Column1 = 1111 and Column2 = 2222
group by Column1, Column2, Column3
having count(*) > 1
此select
查询查找所有重复的行。我想将它们全部删除,因此我将select
更改为delete
:
Delete from Tablename
where Column1 = 1111 and Column2 = 2222
group by Column1, Column2, Column3
having count(*) > 1
我收到一条错误消息,说我无法使用" group by"。
删除所有内容的另一个选择是什么?
答案 0 :(得分:0)
尝试此查询:
with v1 as
(select
ROW_NUMBER() OVER (ORDER BY Column1) AS ID,t1.*
FROM Tablename t1)
DELETE FROM v1 where Column1=1111 and Column2=2222
and id not in (select min(id) from v1 group by
Column1, Column2, Column3);