Table 1:
ID Total1 Total2 Total3
1 10 0 20
1 40 0 50
1 15 0 5
Table 2:
ID Total
1 140
How do i add cumulatively all the rows and find the matching total in table2?
How do i add cumulatively all the rows and find the NOT matching total in table2 and write update statement to update (add those) and write to table2 ?
select sum(t1.total1) + sum(t1.total2) +sum(t1.total3) as "Total" from
table t1, table t2 where t1.ID=t2.ID and sum(t1.total1) +
sum(t1.total2) +sum(t1.total3)=t2.total;
I am not able to get it correctly the update syntax.
Looks like you have the right query to find the totals and match them up. To update rows that don’t have the same total, you could use a correlated subquery like this:
Or with a join (slightly more complicated, but likely faster)