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 trial
count
2,142 PointsStuck on Database Foundations Challenge
I'm stuck on the 3rd task for this challenge.
Here is the answer for the 2nd task.
SELECT AVG(score) AS average FROM reviews GROUP BY movie_id HAVING AVG(score) < 2.
This is the question for the 3rd task "Like before, group by "movie_id" on reviews, select average "score" as "average", filter out averages over 2 and do an outer join on the movies table. Bring back the movie "title" first then the average. Clean up the average and set it to 0 if null."
I just can't seem to figure it out. It does not give the column names for the movies table so I'm not sure what to join on (I have tried movies.id and movies.title). I've tried doing it like in the video (joining the movies table with a LEFT OUTER JOIN to the reviews table as well as altering the Task 2 answer with a RIGHT OUTER JOIN to the movies table ON reviews.movie_id = movies.? Is there something I'm missing?
Answer I tried (but it still says something is wrong with my code):
SELECT title, IFNULL(AVG(score),0) AS average FROM reviews RIGHT OUTER JOIN movies ON reviews.movie_id = movies.id GROUP BY movie_id HAVING AVG(score) < 2 (works in the test db they provided in this section)
1 Answer
Andrew Chalkley
Treehouse Guest TeacherSELECT title, IFNULL(AVG(score),0) AS average FROM reviews RIGHT OUTER JOIN movies ON reviews.movie_id = movies.id GROUP BY movie_id HAVING AVG(score) < 2
Your query will bring back all movies with an average score less than 2 but it will not bring "Tron" who has no reviews yet and therefore it's average is 0.
What happens when you change AVG(score) at the end of your query to average in your test database / code challenge? Your result set should be different :)
Regards
Andrew