Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

SERGIO RODRIGUEZ
SERGIO RODRIGUEZ
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?

Devanshu

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.