您的位置:首页 > 其它

根据属性多少删除指定条件的重复记录!!!

2006-09-30 03:17 393 查看
where col1 in (select col1 from tb as t where t.col1=col1 group by col1 having count(col1)>1) --------根据单属性查重复值
----上面运行结果如下:---
col1 col2
1 a
1 a
1 a
1 a
2 c
2 d
-----------------------
alter table tb add id int identity(1,1)---------加入一标识列,为了处理删除group 中!min(id)的重复记录
go
delete from tb
where col1 in (select col1 from tb group by col1 having count(col1) > 1)
and id not in (select min(id) from tb group by col1 having count(col1 )>1)----删除组中不是最小ID的重复记录
----上面运行结果如下:---
col1 col2 id
1 a 1
2 c 5
3 e 7
4 r 8
----删除多个属性重复记录同理,
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐