zoukankan      html  css  js  c++  java
  • 通过SQL语句删除重复记录

    最近在项目里碰到很多重复记录的事情,因为是设计业务里的具体数值,所以不敢轻易全部删除,数据量也很大,所以就倒腾了点代码在SQL里进行删除

    纯属菜鸟,还望高手指教啊

     1 --创建临时表
    2
    3 ifexists (select*from tempdb.dbo.sysobjects where id=object_id( 'tempdb.dbo.##TEMP'))
    4 droptable ##TEMP
    5
    6 --将有重复记录的数据导入到临时表里,并增添一个字增列
    7 selectIDENTITY(int,1,1) as ppkey,ParameterRelatedId,BusinessParameterID into ##Tempfrom ParameterRelated
    where RegionID='7E01D028-F84A-4D9A-9428-F68989215C0B'and YearTime=2011
    and BusinessParameterID in (select BusinessParameterID from BusinessParameters)
    8
    9 --分组后根据自增列的大小取出重复记录的第一个记录ID
    10 select*from ##Tempwhere ppkey in (selectMin(ppkey) from ##Tempgroupby BusinessParameterID)
    11
    12 --根据取出来的记录ID过滤,删除掉那些重复记录自增列不是最小的记录
    13 deletefrom ParameterRelated where ParameterRelatedId
    notin(select ParameterRelatedId from ##Tempwhere ppkey in
     (selectMin(ppkey) from ##Tempgroupby BusinessParameterID)) 
    and RegionID='7E01D028-F84A-4D9A-9428-F68989215C0B'and YearTime=2011
  • 相关阅读:
    函数式编程
    橡皮筋功能
    socket
    git命令补充说明
    参考接口文档完成的json数据
    接口文档怎么写
    使用json-server创建mock数据
    proxy服务器代理
    Cannot read property 'setState' of undefined错误分析
    使用ref报错,addComponentAsRefTo(...): Only a ReactOwner can have refs.
  • 原文地址:https://www.cnblogs.com/MrWby/p/2176042.html
Copyright © 2011-2022 走看看