利用ROW_NUMBER中的partition by 删除重复Key的数据

With temp As
(
    Select ROW_NUMBER() over(partition by LogisticsPlan order by createon) rowID,ID from LogisticsPlan
    Where LogisticsPlan IN(
    'AGDPM15071704',
    'AGDDE15071401',
    'SGDPM15071404',
    'AGDPM15071404',
    'SGDDE15071104'
    )
)

Delete from LogisticsPlan
where ID IN(
    Select ID from temp where rowID>1
)

 

该情景只用于一个字段数据重复时使用

posted @ 2015-07-17 10:16  Aleax  阅读(319)  评论(0编辑  收藏  举报