我有3个表格,需要通过计算其他两个表格的数据来更新第3个表。
update table3 set column3=
(
select t2.column3+t1.column3
from table2 t2 with (nolock) join table1 t1
on table2.id=t1.id
where table2.id= 100
)
where id= 100;
但是,如果要向本国经营者提供此类服务,则会更新第3栏:
update table3 set column3=
(
select t2.column3+t1.column3
from table2 t2 with (nolock) join table1 t1
on table2.id=t1.id
where table2.id IN (100,101)
)
where id IN (100,101);
这失败了,一收到这一信息
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. The statement has been terminated.
并且,我知道,这是因为分局正在返回1个以上,如何处理这种情况? 任何 h/ough都将是有益的。
How do i update for multiple ids? ie. the select query value returned by ID 100 should be updated against ID 100 in 3rd table & similarly for ID 101.
此外,我需要作一等(t2.coumn3)-(t1.coumn3 + t1.coumn2)
update table3 set column3=
(
select sum(t2.column3)- (t1.column3 + t1.column2)
from table2 t2 with (nolock) join table1 t1
on table2.id=t1.id
where table2.id IN (100,101)
)
where id IN (100,101);