COUNT(*) on its own gives one number for the whole table. GROUP BY sorts the rows into groups that share a value, like sorting cards into piles, and the aggregates then work on each pile separately. You get one result row per group:
SELECT category, COUNT(*) AS products
FROM products
GROUP BY category
ORDER BY category;
The rule to remember: every column in the SELECT list must either be in the GROUP BY or be inside an aggregate. SELECT category, name, COUNT(*) … GROUP BY category makes no sense, because Garden has three products and its one row can only show one name. PostgreSQL and most databases refuse that query. SQLite (and MySQL with some settings) let it through and quietly show the name from one of the rows, which looks right and isn't, so keep to the rule yourself.
NULLs are put together in a group of their own:
SELECT city, COUNT(*) AS customers
FROM customers
GROUP BY city
ORDER BY customers DESC, city;
Returns
city | customers
-------+----------
Austin | 3
Boston | 2
Denver | 2
NULL | 1
(4 rows)
You can group by more than one column: you get one row for each combination that appears. And WHERE still works, filtering the rows before they're put into groups. Shipped orders per customer:
SELECT customer_id, COUNT(*) AS shipped
FROM orders
WHERE status = 'shipped'
GROUP BY customer_id
ORDER BY customer_id;