I have table1 as below:
Col1 Bal
-------------------
1 0
2 0
3 0
4 0
Col1 is the key here.
I have table2 as below:
Col1 Bal Date
---------------------
1 5 x
1 10 y
1 7 z
3 8 p
3 9 m
Col1 is the join column in both tables.
I want to update bal in first table with sum of bal in 2nd table.
What would be the sql statement for this:
update table1 a set a.bal=(select sum(b.bal) from table2) where
and I am lost!
After update, table1 should be:
Col1 Bal
-------------------
1 22
2 0
3 17
4 0
From the documentation, it looks like you can use table aliases in DB2: