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

COUNT GROUP

link: https://teamtreehouse.com/library/reporting-with-sql/aggregate-and-numeric-functions/counting-groups

my code: SELECT genre,COUNT(DISTINCT genre) AS total_genres FROM books GROUP BY genre;

2 Answers

Brian Verdi
Brian Verdi
10,170 Points

Did you get an answer yet? I just ran this and completed it. It looks like your issue is in the count clause. Try COUNT(*). If you use DISTINCT it will only count the rows that are unique in the genre column. Since multiple rows will have the same genre they will not be counted since they are not distinct. Your code will return the number of genres.

Farnoosh Johnson
Farnoosh Johnson
7,887 Points
 select genre, count(*) AS "genre_count" from books group by genre;