首页 > 开发 > 综合 > 正文

如何利用row_number函数处理重复数据

2024-07-21 02:42:07
字体:
来源:转载
供稿:网友

创建测试表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 twhere t.rank = 1go

查看tmp表

select * from dbo.tmpgo

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表