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 trialDan Boswell
2,570 PointsWhy does my SQL statement return 0.0 when using the SUM function?
SELECT SUM(review) AS starman_total_ratings FROM reviews WHERE movie_id = 6;
3 Answers
Dan Boswell
2,570 PointsI solved my own problem.... I was selecting the wrong column (duh!). I needed to SUM the rating column not the review column.
Thomas Nilsen
14,957 PointsUnless "review" is a numerical column, use count(review) instead
Dan Boswell
2,570 PointsThis won't work. I have to use the SUM function in this challenge. Here is the question for context...
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.