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:
- select ColumnA,ColumnB from Table1 where id = 123
- get total sum of the values in ColumnA and ColumnB from all returned records
- 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 )
精彩评论