假如表Users,其中ID为自增长.
ID,Name,Sex
1 张三,男
2 张三,男
3 李四,女
4 李四,女
5 王五,男
--查找出最小行号ID的重复记录
select Name,Sex,Count(1),Mix(ID)
into #TempTable
from Users
group by Name,Sex
having Count(1)>1
--删除重复记录,只保留最小行号的
Delete from Users
from Users as A
inner join #TempTable as B ON A.Name=B.Name And A.Sex=B.Sex
where A. ID<>B.ID
--注意上面表中ID为自增长,如果User表中没有ID自增长,可以虚拟一个ID自增长列。
select IDENTITY(INT) as ID,Name,Sex from Users
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有