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


Packiaraj SanthiyaguRank #659 · 3.6K reputationPosted Jul 4, 2018, 1:15 AM EDT
Kapil Singh KumawatRank #735 · 3.2K reputationPosted Jul 3, 2018, 9:11 PM EDT
Ankit ShuklaRank #2,120 · 672 reputationPosted Jul 3, 2018, 9:17 PM EDT
Kapil Singh KumawatRank #735 · 3.2K reputationPosted Jul 4, 2018, 2:28 AM EDT