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

Development Tools

Wylie Stilwell
Wylie Stilwell
8,785 Points

Grouping, Joining, and Cleaning Up Database Foundations Challenge Question 3

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.

Wylie Stilwell
Wylie Stilwell
8,785 Points

My Answer to the code challenge question is:

SELECT title, IFNULL(AVG(score), 0) AS "Average Score" 
FROM movies RIGHT OUTER JOIN reviews
ON movies.id = reviews.movie_id
GROUP BY reviews.movie_id
HAVING AVG(score) < 2;

But the question says I am wrong. I entered the code into workbench and it ran fine, and outputted movie title then average score of every movie with a score below 2. I think perhaps I am interpreting the question wrong, it seems ambiguous to me. Anyone get this one right?

7 Answers

Wylie Stilwell
Wylie Stilwell
8,785 Points

AHA! GOT IT! THANK YOU MYSELF FOR ANSWERING MY OWN FORUM POST> HOORAY!

Wylie Stilwell
Wylie Stilwell
8,785 Points

Your doing it right. This question is poorly worded and frustrating. The answer is missing only one character:

SELECT movie.title, IFNULL(AVG(score), 0) AS average
FROM reviews RIGHT OUTER JOIN movies
ON reviews.movie_id = movie.id
GROUP BY reviews.movie_id
HAVING IFNULL(AVG(score), 0) <=2;

You can't join on movie.title, you will get null. They have to be the keys that were built together.

And the thing that I forgot, it needs to be <= 2 not < 2.

Thanks this helped. It should be plural movieS

SELECT movies.title, IFNULL(AVG(score), 0) AS average FROM reviews RIGHT OUTER JOIN movies ON reviews.movie_id = movies.id GROUP BY reviews.movie_id HAVING IFNULL(AVG(score), 0) <=2;

Charles Kaelin
Charles Kaelin
4,003 Points

Hey guys,

Appreciate you'll tackling this question. I had spent almost two hours attempting to solve this specific question. Just wanted to add minor clarification(s) to your answers.

At first I attempted to input the final offered answer and for some reason I was still getting an error message. After putting the code in Workbench, I realized "movie.title" needed to be modified to "movies.title". Similar for the "movie.id" needed to be modified to "movies.id".

So, my final answer that FINALLY worked was as follows: SELECT movies.title, IFNULL(AVG(score), 0) AS average FROM reviews RIGHT OUTER JOIN movies ON reviews.movie_id = movies.id GROUP BY reviews.movie_id HAVING IFNULL(AVG(score), 0) <=2;

Hunter MacDermut
Hunter MacDermut
15,865 Points

Thank you for this answer. Andrew sure knows how to make everything seem a lot more difficult than it actually is. Though I guess reaching out to the community of coders for help is part of the learning process.

You can replace the extra IFNULL(AVG(score), 0) at the end with the word average, by the way, since it was calculated and aliased earlier in the query.

Wylie Stilwell
Wylie Stilwell
8,785 Points

Thought maybe i needed to adjust the filter to also display movies with reviews of zed, but that still did not get me the right answer. Ugh this is frustrating.

SELECT IFNULL(AVG(score), 0) as "average" 
FROM reviews RIGHT OUTER JOIN movies 
ON reviews.movie_id = movies.id 
GROUP BY reviews.movie_id 
HAVING IFNULL(AVG(score), 0) < 2;

Still no luck. This question does not list any keys to use in the join method, I will try it without the "ON" statement...

Will Lam
Will Lam
7,027 Points

What was your answer, Wylie?

Will Lam
Will Lam
7,027 Points

This is what I came up with:

SELECT movie.title, IFNULL(AVG(score),0) AS average
FROM reviews OUTER JOIN movies
ON reviews.movie_id=movie.title GROUP BY movie_id 
HAVING average < 2;
Will Lam
Will Lam
7,027 Points

Thanks Wylie!