SQL删除编号最小的重复行

Lju*_*nov 5 sql sql-server duplicate-removal

我找不到合适的方法来删除数字最小的sql表中的重复键.如果存在具有相同Number的重复行,则需要删除其中一个.

例如

Key     Number  Description

11111   5   Desc1
11111   4   Desc2
22222   2   Desc1
22222   2   Desc2
33333   3   Desc1
33333   5   Desc2
Run Code Online (Sandbox Code Playgroud)

在这里,我需要删除第4行,其中第4行小于第5行,第3行或第4行之一,第5行第3行,第3行,第3行,第3行,第5行.

Tec*_*hDo 6

查询以删除SQL Server中的重复:

;with c as
(
    select *, row_number() over(partition by [Key] order by Number desc) as n
    from YouTable
)
delete from c
where n > 1
Run Code Online (Sandbox Code Playgroud)