Databases Reporting with SQL Aggregate and Numeric Functions Counting Groups

How to answer this challenge?


I am trying to answer this question:

In the library database there's a books table. There are id, title, author, genre and first_published columns.

Count all the books in each genre. Include the genre column first and the genre_count as the second column of information.

The code I have written is attached below. I can't figure out what I'm doing wrong so any help will be appreciated!

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

1 Answer

54,281 Points

COUNT(genre) will not include null values. For this use COUNT(*).

You will also want to group by genre since that is what you are counting