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 |
|
DaveC11
Starting Member
43 Posts |
Posted - 2008-10-07 : 06:32:25
|
| have a problem which is prob very simple but it's driving me mad! I've four tablesUsers Targets Placements PlacementConsultantUsers Targetid Placementid PlacementidUserid Userid PlacementFee Useridusername Boardings surname Month I'm trying to write a query that sums the boarding from the target table and placementfee from the placement table and group it by each user.The problem I'm having is that the boarding col is being multiplied by the amount of times that the userid appears in the placementconsultant tableselect u.username +' '+u.surname,sum(total_boarded), sum(placementfee), count(p.placementid) from targets tjoin users u on u.userid = t.useridleft join placementconsultants pc on pc.userid = u.useridjoin placements p on p.placementid = pc.placementidgroup by u.username,u.surnameThanks in advance Dave |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-07 : 06:41:19
|
| [code]select u.username +' '+u.surname,sum(total_boarded), pc1.sumplacement, count(p.placementid) from targets tjoin users u on u.userid = t.useridleft join (select userid,sum(placementfee)as sumplacementfrom placementconsultants pc join placements p on p.placementid = pc.placementidgroup by userid)pc1on pc1.userid = u.useridgroup by u.username,u.surname[/code] |
 |
|
|
|
|
|