转自:http://www.maomao365.com/?p=4942
/*建表*/
create table A(keyId int,info varchar(200))
go
/*生成数据*/
insert into A(keyId,info)values
(1,'a'),(2,'b'),(3,'C'),(4,'d'),(5,'e'),
(1,'a'),(21,'b1'),(31,'C1'),(4,'d'),(51,'猫猫小屋'),
(1,'a'),(6,'b1'),(7,'C1'),(4,'d000'),(10,'maomao365.com')
go
/*删除 keyId重复数据 中的另外几条*/
delete [A2] from
(select row_number() over (Partition By keyId order by keyId) as keyId2,* from A ) as [A2]
where [A2].keyId2 >1
/*
/*删除 所有列都重复数据 中的另外几条*/
delete [A2] from
(select row_number() over (Partition By keyId,info order by keyId) as keyId2,* from A ) as [A2]
where [A2].keyId2 >1
*/
/*展示删除后的数据*/
select * from A
go
truncate table A
drop table A
go
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。