私は3つのテーブルを持っているので、私は他の2つのテーブルからデータを計算して3番目のテーブルのカラムを更新する必要があります。複数のIDの更新ステートメント
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;
このクエリは正常に動作し、それは私がこのような事業者における供給があれば、第三表の列を更新:
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);
これが失敗し、私はこのメッセージ
サブクエリがより多くを返さ取得1値。 =、!=、<、< =、>、> =、またはサブクエリが式として使用されている場合は、これは許可されません。 ステートメントが終了しました。
&サブクエリが1行以上を返しているため、このシナリオをどのように処理できますか?ヒント/考えが役立ちます。
複数IDの更新方法を教えてください。すなわち、 ID 100で返された選択クエリ値は、ID 101と同様に3番目のテーブル&のID 100に対して更新する必要があります。
また、この合計(t2.column3) - (t1.column3 + t1) .column2)
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);
あなたが正しいです、私は内側の条件を必要としません。 – Sharpeye500