Hello,
I have 2 tables.
Table1
Customer | Amount
--------------|------------
A | 10
A | 15
B | 10
B | 5
A | 20
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
4 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Kapil Singh KumawatPosted Jul 4, 2018, 6:28 AM
Packiaraj SanthiyaguPosted Jul 4, 2018, 5:15 AM
Ankit ShuklaPosted Jul 4, 2018, 1:17 AM
Kapil Singh KumawatPosted Jul 4, 2018, 1:11 AM