27,579
社区成员
发帖
与我相关
我的任务
分享
create table T(pid int primary key,id int,name varchar(20))
insert into t select 1,4,'a'
insert into t select 2,4,'b'
insert into t select 3,4,'c'
insert into t select 4,43,'d'
insert into t select 5,42,'e'
insert into t select 6,4,'f'
select pid,identity(int,1,1) as id into # from T order by pid
update T set id=b.id from T as a inner join # as b on a.pid=b.pid
select * from t
/*
1 1 a
2 2 b
3 3 c
4 4 d
5 5 e
6 6 f
*/