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