我通过此查询在SQL Server中发现了大量重复数据
SELECT
[MærkeID], [Model], [Årgang], [Motor Type], [Krydsmålet],
[Centerhul], [Bolter], [Dæk], [Fælge], [ET], [vendor], COUNT(*)
FROM
Data.Hjuldata
GROUP BY
[MærkeID], [Model], [Årgang], [Motor Type], [Krydsmålet],
[Centerhul], [Bolter], [Dæk], [Fælge], [ET], [vendor]
HAVING
COUNT(*) > 1
有没有办法删除它们所以只有1条记录而不是2条记录?
答案 0 :(得分:2)
WITH X AS (
SELECT
*
,ROW_NUMBER() OVER (PARTITION BY
[MærkeID]
,[Model]
,[Årgang]
,[Motor Type]
,[Krydsmålet]
,[Centerhul]
,[Bolter]
,[Dæk]
,[Fælge]
,[ET]
,[vendor] ORDER BY (SELECT NULL)) RN
FROM Data.Hjuldata )
DELETE FROM X
WHERE RN > 1