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 trialIan Corritore
4,740 PointsGroup, Joining, and Filter in SQL.
I am stumped on this segment: 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, filter out any "average" score over 2. Here is my code:
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;
Where am I going wrong?
1 Answer
bothxp
16,510 PointsHi Ian,
My answer was:
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;
It looks like you have a . instead of a , in the IFNULL
Dave McFarland
Treehouse TeacherDave McFarland
Treehouse TeacherHi Ian,
Your SQL code wasn't showing up correctly. I fixed it in your post. For the future, to put code in a forum post:
hit return to create a new line and type three back tick characters ```
hit return to create another new line and paste your HTML
hit return and add three more back tick characters: ``` The back tick character isn't the same as the single quote -- ' -- mark; the back tick is located on the same key as the ~ on most keyboards.
Also to add correct color highlighting add the name of the language after the back ticks like this: ```CSS. Here's what CSS should look like in a forum post: