TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ankit Shukla
NA
681
116.8k
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
Reply
Answers (
4
)
Convert two columns into key-value json object?
sql procedure for select and insert at same time