sql server 表去除重复行

1、有唯一列,通过唯一列最大或最小方式删除重复记录

1 delete from zczjDataTemp
2   where cdnum in( select cdnum from zczjDataTemp group by  cdnum having count(cdnum ) > 1) and 
3  ID not in(select  max(ID) from zczjDataTemp group by  cdnum having count(cdnum ) > 1 )

2、无唯一列使用ROW_NUMBER()函数删除重复记录

1 Delete T From
2  (Select Row_Number() Over(Partition By [cdnum] order By [ID]) As RowNumber,* From zczjDataTemp)T
3  Where T.RowNumber > 1

确认SQL

1 select T.* From
2   (Select Row_Number() Over(Partition By [cdnum] order By [ID]) As RowNumber,* From zczjDataTemp)T
3   Where T.RowNumber = 1

 

sql server 表去除重复行

上一篇:MongoDB聚合查询


下一篇:mysql 常用函数---日期函数