利用row_number函数处理重复数据

 
利用row_number函数处理重复数据
 
--创建测试表person
CREATE TABLE person(
    sn varchar(10),
    name varchar(50)
);
go
 
--插入测试重复数据
insert into person values('1','guoqiang1');
insert into person values('1','guoqiang1');
insert into person values('1','guoqiang1');
insert into person values('2','guoqiang2');
insert into person values('2','guoqiang2');
insert into person values('3','guoqiang3');
go
 
--查看person
select * from dbo.person;
go
 
--去除重复数据,并放到tmp表中
select sn,name into tmp from
(select *, row_number() over(partition by sn order by sn) as rank from person) as t
where t.rank = 1
go
 
--查看tmp
select * from dbo.tmp
go
 
 
posted @ 2008-02-18 13:00  深潭  阅读(675)  评论(0编辑  收藏  举报