zoukankan      html  css  js  c++  java
  • SQL Sever 刪除重複數據只剩一條

    use book

       go

      

       create table ##T1(

         n int,

         a nvarchar(20)  

       )

      

       --查詢重複記錄,插入臨時表

       insert into ##T1(n,a) 

       select suid,WorkID from HR_Duty_EmpSchedule_M

       where WorkID in (select WorkID  from HR_Duty_EmpSchedule_M  group by WorkID having count(WorkID) > 1)

       and DutyDate ='2018/11/26'

       order by WorkID

      

      select * from ##T1

      

       create table ##T2(

          m int,

          a nvarchar(20)

       )

       --查詢

      

       select min(n) as N  from ##T1 group by a having count(a)>1

      

       insert into ##T2(m,a)

       select n,a from ##T1 where n not in ( select min(n) as N  from ##T1 group by a having count(a)>1)

      

       select * from ##T2

      

       select * from HR_Duty_EmpSchedule_M X,##T2 Y  where X.SUID=Y.m order by WorkID

      

       --delete from HR_Duty_EmpSchedule_M  where SUID in (select m from ##T2)

      

       

       drop table ##T1

       drop table ##T2

    好好學習。天天向上
  • 相关阅读:
    [转]find高级用法
    svn服务器配置
    awk (一)
    Linux下恢复ext3文件系统误删除文件ext3grep
    cobbler无人值守安装操作系统
    Linux下virtualbox网络配置
    nginx+uwsgi来部署Django
    solaris 网络设置
    rpm 使用说明
    linux 下安装mysql
  • 原文地址:https://www.cnblogs.com/ximi07/p/10276516.html
Copyright © 2011-2022 走看看