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

david hollaway
david hollaway
15,771 Points

SUM function() help

https://teamtreehouse.com/library/reporting-with-sql/aggregate-and-numeric-functions/summing-values Here's the question:

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 for the movie "Starman" in the reviews table. Alias it as starman_total_ratings.

Type in your command below. Bummer! Your query didn't perform the correct sum calculation.

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

What am I doing wrong?

2 Answers

Steven Parker
Steven Parker
229,732 Points

I see 3 potential issues:

  • the movie_id is a numeric field, but you're comparing it with a string
  • the instructions only ask for the sum, the rating column itself should probably not be returned
  • you probably don't need "GROUP BY"

If that's not everything, provide a link to the course page to enable a more complete analysis.

david hollaway
david hollaway
15,771 Points

Thanks. This worked:

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

Steven Parker
Steven Parker
229,732 Points

david hollaway — Glad I could help. But normally, you would choose the answer that helped resolve the issue as "best answer". Choosing your own response might be confusing to someone reading the question laster.