I have 2 tables.
Table2
Customer | Amount
--------------|------------
A | 5
A | 10
B | 8
B | 5
I need to get (total amount of Table1) - (total amount of Table2) group by Customer
Output
Customer | Amount
--------------|------------
A | 30 (45 - 15)
B | 2 (15 - 13)
My Query:
Select Table1.Customer, sum(Table1.Amount) - sum(Table2.Amount) from Table1 inner join Table2 On Table1.Customer = Table2.Customer group by Table1.Customer
But it gives wrong output.
Please help.
Thanks