IT Gourmet
数据仓库, ETL的笔记

用了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

 

posted on 2014-04-23 17:53  ImToffee  阅读(177)  评论(0编辑  收藏  举报