删除重复数据,保留最新数据

先查看重复数据:

查看字段id1,id2重复的,按uptime倒序排列

select * from
(select ROW_NUMBER() over(partition by id1,id2 order by uptime desc) as row_number,
 *from ku.dbo.biao) T
 where T.row_number>1;

 

删除重复数据,保留最新数据

delete T from
(select ROW_NUMBER() over(partition by id1,id2 order by uptime desc) as row_number,
 *from ku.dbo.biao) T
 where T.row_number>1;

 

 

 

 

 

 

你可能感兴趣的:(数据处理,sql)