开发者

plsql updatee a table value based on the sum of values from another table

I'm trying to update a table based on the sum of values from another table. The process I want to follow is:

  1. select ColumnA,ColumnB from Table1 where id = 123
  2. get total sum of the values in ColumnA and ColumnB from all returned records
  3. update Table2's columnC with the total sum from above * 5 (or some value) where id =123

So if the return record from 'select ColumnA,ColumnB from Table1 where id = 123

开发者_如何学运维
ColumnA ColumnB
1           5
3           0
1           7

And Table2's columnC would be set to (1+3+1+5+0+7) * 5 where id = 123

Thanks!


You don't need PL/SQL for that.

UPDATE TABLE2 
SET  COLUMNC = ( SELECT (SUM(ColumnA + ColumnB))*5
                 FROM TABLE1 
                 WHERE id = 123 )
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜