使用cte中的rank()函数删除重复记录

时间:2019-04-04 11:01:26

标签: sql-server-2008

   with DeleteDUplicateinXYZ
    as
    (
     Select ID, rank()over( order by Id Asc) as [rank] 
     from ppp        -----------never use 'partion by' while using rank
    )Delete from DeleteDUplicateinXYZ 
    where [rank] in (Select id, count([rank]) 
    from DeleteDUplicateinXYZ group by Id having count([rank]) >=2)

0 个答案:

没有答案