17

テーブルから重複レコードを削除するクエリを作成しました

;WITH a as
(
SELECT Firstname,ROW_NUMBER() OVER(PARTITION by Firstname, empID ORDER BY Firstname) 
AS duplicateRecCount
FROM dbo.tblEmployee
)
--Now Delete Duplicate Records
DELETE FROM tblEmployee
WHERE duplicateRecCount > 1 

しかし、どこで間違ったのかわかりません

列名が無効ですduplicateRecCount

誰かが私を助けることができますか?

4

2 に答える 2

41

deleteステートメントでCTEを参照する必要があります...

WITH a as
(
SELECT Firstname,ROW_NUMBER() OVER(PARTITION by Firstname, empID ORDER BY Firstname) 
AS duplicateRecCount
FROM dbo.tblEmployee
)
--Now Delete Duplicate Records
DELETE FROM a
WHERE duplicateRecCount > 1
于 2013-02-24T16:48:34.897 に答える
9
 DELETE duplicates FROM
(SELECT ROW_NUMBER() OVER (PARTITION BY firstname, lastname, EMPNO, salary,dept  ORDER BY empno) cnt
 FROM tblEmp)  duplicates
WHERE duplicates.Cnt > 1
于 2013-04-14T10:28:46.620 に答える