Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Development Tools

SQL Calculating,Aggregating and other functions task 2 keeps throwing an error

task 2 of SQL Calculating,Aggregating and other functions keeps throwing an error even though query seems to run with the correct results??

my query is as follows

select avg(score) as average from reviews group by movie_id HAVING average > 2;

4 Answers

Yeah, this is a bad query too. :)

You have a couple of mistakes. First you need the title FROM movies and then join it with the reviews.

The places of movies.id and reviews.id have to be the backward order (and you have a typo there... reviews.movie_id ).

Then on the outer join you need to specify LEFT OUTER JOIN so the title of the movie is the base.

And last, you've made the same mistake with the filtering. The sign has to be <.

The query should look like that:

select title, IFNULL(avg(score), 0) as average 
from movies 
on movies.id = reviews.movie_id
group by movie_id HAVING average < 2;

Oh, this one is tricky. I've spend a lot of time on this too. :)

The only problem is in the > sign. It has to be <.

The task says filter out any averages over 2, so you don't want any data elements over that. You want all elements having less that 2.

Good luck!

Thanks tihomirvelev

that worked now task three is driving me up the wall.

select title,IFNULL(avg(score),0) as average from reviews OUTER JOIN movies on reviews.id=movies.id group by movie_id HAVING average > 2;

it says something is wrong with my OUTER JOIN

thanks mate for all your help!