假设id
不能复制,您可以执行以下操作:
;WITH CTE AS
(
SELECT id,
operation,
age,
shoesize,
N = COUNT(*) OVER(PARTITION BY operation, age, shoesize)
FROM YourTable
)
DELETE FROM CTE
WHERE N > 1
OR operation = 'R -'
OR shoesize < 0
如果id
需要考虑重复,则:
;WITH CTE AS
(
SELECT id,
operation,
age,
shoesize,
N = COUNT(*) OVER(PARTITION BY id, operation, age, shoesize)
FROM YourTable
)
DELETE FROM CTE
WHERE N > 1
OR operation = 'R -'
OR shoesize < 0
如果您只需要删除重复的行,并且想要保留其中的一行,那么您需要执行以下操作:
;WITH CTE AS
(
SELECT id,
operation,
age,
shoesize,
RN = ROW_NUMBER() OVER(PARTITION BY id, operation, age, shoesize ORDER BY id)
FROM YourTable
)
DELETE FROM CTE
WHERE RN > 1
OR operation = 'R -'
OR shoesize < 0