Ankit  Shukla

Ankit Shukla

  • NA
  • 681
  • 110.6k

Need Query for this output

Jul 4 2018 1:02 AM
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 
 

Answers (4)