代码改变世界

用SQL语句去掉重复的记录

2017-12-11 18:23  输入杰  阅读(221)  评论(0)    收藏  举报

delete tmp from( 

       select row_num = row_number() over(partition by 字段,字段 order by 时间 desc)   from 表 where 时间> getdate()-1  

 ) tmp   where row_num > 1   

 

 

  delete from 表 where 主键ID not in(  

           select max(主键ID) from 表 group by 需要去重的字段 having count(需要去重的字段)>=1  

 )