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 trialJan Lundeen
5,886 PointsCalculating average ratings for Starman - Getting an error that the movie_id column doesn't exist.
Hi,
In the Reporting for SQL class, I'm getting an error on my AVG query. I'm not sure why this is happening. Here's the question:
Challenge Task 1 of 1 We're in a movie database. There's a reviews table with the columns of id, movie_id, username, review andrating. 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.
Here's my query:
SELECT AVG("rating") AS "average_rating" WHERE movie_id = 6;
Here's the error:
SQL Error: no such column: movie_id
Originally, I didn't have quotes around (rating). When I ran my original query, it said that "SQL Error: no such column: rating." At first, I thought I misspelled rating, but the spelling looks okay. When I put quotes around rating [("rating")], that changed the error message to SQL Error: no such column: movie_id". I checked my spelling again. The spelling of movie_id was okay. Then, I put quotes around movie_id to see if that would help. It didn't. I'm not sure why it continues to give me this error. Any ideas?
Thanks,
Jan
1 Answer
Steven Parker
231,248 PointsYour query is missing the FROM
clause.
Before the WHERE
clause, there should be a FROM
clause identifying the table.
Once you fix that, you probably won't need the quotes around the column name.
Jan Lundeen
5,886 PointsJan Lundeen
5,886 PointsHi Steven,
Oh my, what a wahoo I am.:). I overlooked that completely. No wonder it was saying there was no such column.
Thanks,
Jan