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 Database Foundations SQL Calculating, Aggregating and Other Functions Grouping, Joining and Cleaning Up

Database Foundations Challenge

I'm dying!

Darren Joy
Darren Joy
19,573 Points

I hear yah brutha!

I need to go through that stuff again too. I got about 2/3rds of the way through and had to take a break...

It's not so much hard, as tedious. I just can;t remember all the little nuances of calling this and wildcarding that.

4 Answers

Don't know if you managed to figure this one out... but correct answer is:

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

Thanks, Lucy. My mistake was different, but your reply helped me out to by going through your reply.

Like before, select the average "score" as "average", setting to 0 if null, by grouping the "movie_id" from the "reviews" table. Also, do an outer join on the "movies" table with its "id" column and display the movie "title" before the "average". Finally, include averages under 2.

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

What's wrong with it? :'(

Carsten Dollerup
Carsten Dollerup
9,278 Points

I hope this helps someone, as I was a bit confused about this one too.

Julius' problem was trying to get the title from the reviews table. My mistake was trying to join the tables with: "...FROM reviews LEFT OUTER JOIN movies"... which obviously then does not generate the movie which has no scores. That's why the "RIGHT OUTER JOIN movies..." is correct to use.

Best Regards and keep it up all! :-)

Amed Alberto Sanchez
Amed Alberto Sanchez
Python Development Techdegree Student 2,879 Points

The correct answer is:

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

Courtesy of Eric Butler. Check the other discussion on this topic https://teamtreehouse.com/community/code-challenge-3-2