Reputation: 49
I have two tables named T1
and T2
. Both of the tables have a column in common called balance. How can I get the difference between the two sums of the two tables.
Example:
T1
balance
-------
100
50
The sum for T1
would be 150 (100 + 50)
T2
balance
-------
100
200
The sum for T2
would be 300 (100 + 200)
So I would like the output to give me the result 150 (sumT1-sumT2).
Upvotes: 0
Views: 40
Reputation: 28890
Just sum and select from tables ..
select (select ifnull(sum(balance),0) from t2)-(select ifnull(sum(balance),0) from t1) as balance
Upvotes: 1