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 Reporting with SQL Aggregate and Numeric Functions Counting Groups

NOT understanding

SELECT COUNT genre FROM books GROUP BY genre_count;

2 Answers

Tomas Schaffer
Tomas Schaffer
11,606 Points

SELECT COUNT(genre) genre_count FROM books GROUP BY genre_count;

But what is the reason to group the results of one column? Because this query is the result of one record.

This Query counts the number of result.

SELECT COUNT(*) genre_count FROM books;

So this is the same with better performance because you dont select all data just counting rows of table:

SELECT COUNT(0) genre_count FROM books;

Steven Parker
Steven Parker
231,269 Points

Did you actually try any of those as answers to the challenge? :see_no_evil:

Tomas Schaffer
Tomas Schaffer
11,606 Points

You didn't put the link to challenge. I didn't even know thats from challenge. But i work with PostgreSQL. So post the link to challenge if you like to.

Steven Parker
Steven Parker
231,269 Points

The link to the challenge is the colored button in the upper right of this page that says "View Challenge".
The system put it there automatically when Derek created this question.

Tomas Schaffer
Tomas Schaffer
11,606 Points

OK I am sorry didnt se the button.This is the correct answer.

SELECT genre, count(0) as genre_count FROM books GROUP BY genre;

Tomas Schaffer
Tomas Schaffer
11,606 Points

I didn't see first time button to Challenge and didn't see whole question. The right Answer to Challenge is below Derek.

SELECT genre, count(0) as genre_count FROM books GROUP BY genre;