Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSharina Jones
Courses Plus Student 18,771 PointsQuery producing incorrect results
I've entered the following query, but the results I get don't match the video. I can't figure out where I've gone wrong. Any help would be greatly appreciated.
--combined as subqueries
SELECT sr.LastName, Loc1.StLouisAmount, Loc2.ColumbiaAmount FROM SalesRep AS sr
LEFT OUTER JOIN(
SELECT SalesRepID, SUM(SaleAmount) AS StLouisAmount
FROM Sale AS s WHERE s.LocationID = 1
GROUP BY SalesRepID
) AS Loc1 ON sr.SalesRepID = Loc1.SalesRepID
LEFT OUTER JOIN(
SELECT SalesRepID, SUM(SaleAmount) AS ColumbiaAmount
FROM Sale AS s WHERE s.LocationID = 2
GROUP BY SalesRepID
) AS Loc2 ON sr.SalesRepID = Loc1.SalesRepID;
Thanks.
2 Answers
Emmanuel C
10,636 PointsHey Sharina,
The last line
AS Loc2 ON sr.SalesRepID = Loc1.SalesRepID;
I believe should be
AS Loc2 ON sr.SalesRepID = Loc2.SalesRepID;
Different temp table.
Jorgen Rasmussen
3,367 PointsDon't Feel Silly Sharina I just did the same thing and this question was very helpful
Sharina Jones
Courses Plus Student 18,771 PointsSharina Jones
Courses Plus Student 18,771 PointsThank you! I feel so silly, lol!