答案 0 :(得分:3)
您可以使用ROW_NUMBER()
删除重复项:
with duplicates as
(
select
*
,ROW_NUMBER() OVER (PARTITION BY FirstName, LastName, age ORDER BY FirstName) AS number
from yourTable
)
delete
from duplicates
where number > 1
number
大于1的每一行都是重复的。
答案 1 :(得分:3)
您可以使用公用表表达式来删除一组重复项中除第一条记录以外的所有记录:
with cte as (
select *, row_number()
over (partition by FirstName, LastName, Age order by FirstName, LastName, Age) as row_number
from tbl
)
delete from cte where row_number <> 1
答案 2 :(得分:1)
您需要某种在没有PK的情况下识别行的方法。
我唯一想到的方法是:
不过,我对此解决方案并不满意。我认为this answer可以帮助产生独特的行ID。希望对您有所帮助。