34,590
社区成员
发帖
与我相关
我的任务
分享
--> 测试数据:[test]
if object_id('[test]') is not null drop table [test]
create table [test](
[id] int,
[seq] int,
[context] varchar(5),
constraint id_seq_pk primary key([id],[seq])
)
insert [test]
select 1,1,'test1' union all
select 1,2,'test2'
with t
as(
select * from test
)
update test
set seq=t.seq from t
where t.seq<>test.seq
select * from test order by seq desc
/*
id seq context
1 2 test1
1 1 test2
*/
--仅仅是一个思路,解决你现在给的这个特殊数据没问题
update tb set context=test2 where seq=1
update tb set context=test1 where seq=2
select * from tb