Coginiti menu Coginiti menu

How to Have Multiple Counts

You can use the COUNT function in combination with the GROUP BY clause to have multiple counts on the same query.

To count the number of books per category and the number of books published in a particular year, you can use the following query:

SELECT category, publish_date,  
COUNT(*) as count  
FROM books GROUP BY category,publish_date; 

In this example, the GROUP BY clause groups the results by category and publish_date. The COUNT function calculates the number of books in each group.