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!

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

General Discussion

Database Foundations : Stage 7, Step 4, Grouping, Joining and Cleaning Up :: Code Challenge : 1 of 3

The challenge is :

Group all reviews by "movie_id" and get the average "score" and alias it as "average".

My sql query for the same :

select movie_id, avg(score) AS average from reviews group by movie_id;

I am getting a valid output with the error "Oops! There is something wrong with your query"

I can't preview what this 'something' is and I am unable to proceed to the next challenge. Please help me!

The link to the challenge is : http://teamtreehouse.com/library/grouping-joining-and-cleaning-up

1 Answer

17,532 Points

Try this

SELECT  avg(score) AS average FROM reviews GROUP BY movie_id;

Hope this helps!

Thanks !

This works. But while grouping by an attribute, isn't it only logical that the attribute should be visible along with the aggregated data?


Yes - it's extremely logical, and very good practices, I'm finding that ALL the challenges in this exercise not only teach poor practices but are god awfully written so you can't get the right answer

Kris Phelps
Kris Phelps
7,609 Points

Thanks Sergio. That exercise didn't even give the name of the database like previous exercises did. That was a very poorly written exercise.

It would be nice if they let you run SQL to help figure things out. I was trying things like:

SELECT * FROM movies; and SELECT * FROM reviews;

Just to figure out which database I should be using for the exercise, but no luck. LOL.