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

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 Points

Help with SUM(), GROUP BY, WHERE (HAVING?)

We have this challenge:

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 the id of 6. Movie ids are found in the movie_id column in the reviews table. Write a query that totals up all ratings in the reviews table. Alias it as starman_total_ratings.

Here is my answer:

SELECT SUM(rating) AS starman_total_ratings, movie_id FROM reviews WHERE movie_id = 6;

Error message: Bummer! Your query didn't perform the correct sum calculation.

Output:

Imgur

It seems like I am getting the correct output. I can't figure out what's wrong. Also, the last video was all about using GROUP BY and HAVING but this challenge doesn't seem to want those things when I try and use them.

2 Answers

Matthew Brock
Matthew Brock
16,791 Points

The query looks correct, but it may be as simple as they did not ask for the movie id in the query. Try just

SELECT SUM(rating) AS starman_total_ratings FROM reviews WHERE movie_id = 6;
Andrew Winkler
Andrew Winkler
37,739 Points

matthew is right. it should be:

SELECT SUM(rating) AS starman_total_ratings FROM reviews WHERE movie_id = 6;

I did this challenge yesterday.