开发者

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

开发者 https://www.devze.com 2023-01-30 09:29 出处:网络
I\'m trying to update a table based on the sum of values from another table.The process I want to follow is:

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

精彩评论

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