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

Y B
Y B
14,136 Points

SQL challenge GROUP BY

I can't get past the group by challenge in the mySQL course. The question asks: Group all reviews by "movie_id" and get the average "score" and alias it as "average".

but my answer:

SELECT AVG(*) AS average FROM movies GROUP BY movie_id

doesn't seem to work?

5 Answers

Ahh, it's because the 'score' column is in the 'reviews' table.

Try:

SELECT AVG(score) AS average FROM reviews GROUP BY movie_id 
Saira Bottemuller
Saira Bottemuller
Courses Plus Student 1,749 Points

Thank you so much, I was stuck on this one as well. At first I'd thought my input was exactly what you wrote here, but after reviewing it, I was trying to use SELECT movie_id, AVG(score) AS average FROM reviews GROUP BY movie_id; which is incorrect! So you can just directly select AVG(score) then?!

Try:

SELECT AVG(score) AS average FROM movies GROUP BY movie_id
Y B
Y B
14,136 Points

Unfortunately it still doesn't like that the error is:

SQL Error: Unknown column 'score' in 'field list'

Y B
Y B
14,136 Points

ah good spot thanks.

SELECT AVG(score) AS average FROM reviews GROUP BY movie_id;

don't forget the parentheses...