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

Databases

SQL error

SELECT AVG(rating) WHERE movie_id=6 AS average_rating FROM reviews;

What is incorrect about this statement? Thank you.

3 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Hi Danielle. Looks like you've got all the right information in there although to verify this I'd need to see the question but you need to put the alias of the column you're selecting next to the actual SELECT column. Try making sure the WHERE clause is the last part of your query.

SELECT AVG(rating) AS average_rating FROM reviews WHERE movie_id=6;

Good luck!

Mod Note: I also changed the topic from Digital Literacy to Databases

Thank you! I suppose linking to the question might have been helpful, lol.

We're in a movie database. There's a reviews table with the columns of id, movie_id, username, review >and rating. The movie "Starman" has an id of 6. Movie ids are stored in the movie_id column. Calculate the average >rating for "Starman". Alias the average as average_rating.

The question can be found here I was able to move forward by adding space between the equal sign and number for movie id, like so

WHERE movie_id = 6;

Thanks for the response!

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

No worries.

Just check my original post and try the query if you haven't already. It should pass. :-)

Tommy Gebru
Tommy Gebru
30,164 Points

For these exercises I keep forgetting or overlooking the rating parameter or column... :bulb: