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

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 
LEFT OUTER JOIN reviews
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!