用了aggregate函数和temp表。在SQLServer 2008下执行通过。
可以处理存在不同主键的重复数据。
create table t
(a int,
b char(10),
c char(10)
)
insert into t values (1, 'aa','bb')
insert into t values (2, 'aa','bb')
insert into t values (3, 'aa','bb')
insert into t values (4, 'cc','bb')
insert into t values (5, 'cc','bb')
insert into t values (6, 'aa','cc')
with tmp as(
select a,row_number () over ( partition by b,c order by b,c) as rownum from t
)
delete from tmp where rownum<>1
select * from t
本文介绍了一种使用SQL Server 2008中的aggregate函数和temp表来处理具有不同主键的重复数据的方法。通过创建临时表并利用row_number()函数,可以有效地删除除了每组第一条记录之外的所有重复项。

被折叠的 条评论
为什么被折叠?



