2016-09-02 7 views
0

oracleの内部ビューを使用して複数の行を更新しようとしています。Oracleで異なる値を持つ複数の行を更新します。

このビューを更新するためのselect文は次のとおりです。私がしようとしています

select count(distinct a.numCount) as numCount, a.accNum as accNum , 
s.unitNum as unitNum 
from tableA a,tableS s where a.accNum is not null and s.fk_id= 
(select id from tableD where sid=a.accNum) 
group by a.accNum ,s.unitNum ; 

UPDATE文は以下の通りです:

update 
(select count(distinct a.numCount) as numCount, a.accNum as accNum , 
s.unitNum as unitNum 
from tableA a,tableS s where a.accNum is not null and s.fk_id= 
(select id from tableD where sid=a.accNum) 
group by a.accNum ,s.unitNum) k 
set k.unitNum=k.numCount; 

私はnumCountの値でunitNumを更新しようとしています。 上記のクエリは、ビューとして使用すると機能しません。 これをOracleで更新する別の方法はありますか?

お勧めします。テーブルの

構造は以下の通りです:

TableA 

accNum numCount 
----------------------- 
111  1 
222  5 
333  2 
111  1 
111  1 
222  5 
222  2 


TableS 

fk_id unitNum 
----------------------- 
123  0 
768  0 
734  0 

TableD 

ID  sid 
----------------------- 
123  222 
768  111 
734  333 

出力は以下のようにする必要があります:

TableS 

fk_id unitNum 
----------------------- 
123  3 
768  3 
734  1 

上記のクエリが更新されてどのように

+0

を提案してください? –

+0

テーブルの構造について詳しく説明できますか? –

+1

私たちに 'update'ステートメントを教えてください –

答えて

0
update tableS s 
    set unitNum= 
     (select count(distinct a.numCount) as numCount 
      from tableA a, tableD d 
      where s.fk_id=d.id and d.sid=a.accNum 
     ); 
関連する問題