34,587
社区成员
发帖
与我相关
我的任务
分享
id code subject answer
1 001 Q11 1
1 001 Q11_y 1
1 002 Q11 2
1 002 Q11_y 1
1 003 Q11 1
create table #test
(
id int,
code varchar(10),
[subject] varchar(20),
answer int
)
insert into #test
select 1,'001','Q11',1 union all
select 1,'001','Q11_y',1 union all
select 1,'002','Q11',2 union all
select 1,'002','Q11_y',1 union all
select 1,'003','Q11',1
update #test set answer=2
from (select * from #test where [subject]='Q11' and answer=1) a
where a.code=#test.code and #test.[subject]='Q11_y'
select * from #test
id code subject answer
----------- ---------- -------------------- -----------
1 001 Q11 1
1 001 Q11_y 2
1 002 Q11 2
1 002 Q11_y 1
1 003 Q11 1
(5 行受影响)