sqlserver 清掉工件号重复的数据

单主键

  with T as( 
                SELECT ROW_NUMBER() over (PARTITION By 工件号 order by 检测时间 desc) as rowid,* FROM 检测表   
)
 delete from T where id not in( select id from T where rowid = 1)

 

组合主键

with T as( 
                SELECT ROW_NUMBER() over (PARTITION By     MachineCode,Content,CreationTime order by id ) as rowid,* FROM [OperationRecords2021-03-01]   
)
 delete from T where id not in( select id from T where rowid = 1)

 

posted @ 2020-10-26 15:26  も不秃不秃  阅读(169)  评论(0编辑  收藏  举报