美文网首页
过滤重复数据

过滤重复数据

作者: Asa_Guo | 来源:发表于2017-04-18 08:33 被阅读0次
 --1.创建临时表
 select * 
   into #Tmp
   from
   --过滤重复数据,留下相同记录中ID最小的一条数据。比如name相同的记录,我要ID最小的
     (select * 
        from [HL7].[dbo].Test a 
       where not exists 
             (select 1 
                from [HL7].[dbo].Test 
               where Name = a.Name and ID < a.ID)
      ) as table1
 --2.删除旧表
drop table [HL7].[dbo].Test 
 --3.还原旧表
select * into [HL7].[dbo].Test from #Tmp 
 --4.删除临时表
drop table #Tmp 

相关文章

网友评论

      本文标题:过滤重复数据

      本文链接:https://www.haomeiwen.com/subject/yajgmttx.html