Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
man889
Starting Member
25 Posts |
Posted - 2011-06-14 : 03:53:29
|
I have two table as followTableAPID, Amount11, 101, 202, 102, 103, 30TableBPID, Amount21, 201, 502, 302, 20SELECT TableA.PID, Sum(TableA.Amount1) AS Amount1OfSum, Sum(TableB.Amount2) AS Amount2OfSumFROM TableA left JOIN TableB ON TableA.PID = TableB.PIDGROUP BY TableA.PID;The output isPID, Amount1, Amount21, 90, 2002, 20, 403, 30, What I want the output isPID, Amount1, Amount21, 30, 702, 20, 503, 30, Thank. |
|
raghuveer125
Constraint Violating Yak Guru
285 Posts |
Posted - 2011-06-14 : 05:10:54
|
Try thisSelect t.Pid,t.Amount1,tt.Amount2 from (SElect pid,Sum(Amount1) as Amount1 from tableA Group by Pid) as t left join(Select pid,Sum(Amount2) as Amount2 from tableB Group by Pid)as tt on t.pid=tt.pidIn Love... With Me! |
|
|
man889
Starting Member
25 Posts |
Posted - 2011-06-14 : 05:21:00
|
Hi raghuveer125,Thank for your's replyI will try it tmr |
|
|
man889
Starting Member
25 Posts |
Posted - 2011-06-14 : 21:55:18
|
Hi raghuveer125,I got it, thank. |
|
|
|
|
|
|
|