SQL Sever 刪除重複數據只剩一條
2024-08-27 00:23:48
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
最新文章
- memcache and redis 的区别
- JAVA 如何把request请求的参数,快速放到model对象中
- 【JSP手记】--jsp里面session.getAttribute(";×××";)在java中的表示
- MVC5-11 浅谈拦截器
- 从0到1---“保多多”APP的开发(二)
- 编程语言 IDE 对比
- stream转byte数组几种方式
- 完美解决VMware Workstation : Could not open /dev/vmmon: No such file or directory
- onmousedown活用之鼠标拖动
- 海思Hi3559A/CV100 DDR4驱动配置手册
- [翻译 EF Core in Action] 1.5 关于NoSql
- work-7.2
- linux jpg文件查找木马
- 配置3层交换机VLAN间通信
- Java学习笔记之——Manth类和String类
- VirtualBox下扩容vdi文件
- 静态代码检查findbugs/阿里巴巴开发规范
- numpy广播
- spring 解耦
- Graph
热门文章
- OpenGL ES: (5) OpenGL的基本概念、OpenGL ES 在屏幕产生图片的过程、OpenGL管线(pipeline)
- 002 centos7中遇到的问题
- Docs-.NET-C#-指南-语言参考-关键字-值类型:可以 null 的值类型
- spring boot集成Websocket
- 【427】Graph 实现 以及 DFS &; BFS
- Linux使用sleep进行延迟实验
- 【Leetcode_easy】941. Valid Mountain Array
- shell每隔一秒钟就记录下netstat状态
- Redis概述与基本操作
- BASH输出着色显示