SQL
Public
Count Rows by Category
Count how many records belong to each category.
#sql
#group-by
#count
#report
SQL
SELECT category_id, COUNT(*) AS total_items
FROM products
GROUP BY category_id
ORDER BY total_items DESC;
Notes
GROUP BY is one of the most useful SQL tools for summaries and reports.