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 Reporting with SQL Aggregate and Numeric Functions Averaging Values

Query regarding calculating average

I made a few attempts to calculate the average for movie ratings, I feel like im missing something but can#t pinpoint what it is, any pointers is much appreciated.

SELECT AVG(rating) AS average_rating, movie_id FROM reviews GROUP BY movie_id HAVING movie_id = 6;

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

regards

1 Answer

Hi Taher,

It appears the only issue is that the teacher wants you to return one column instead of two. In your query you have the average and the movie_id column returned in the SELECT statement. Just take away the extra column and your query will pass. It should look something like this:

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

Cheers!