GROUP BY category partitions rows, then COUNT(*) counts every row per group.

highlighted = computed this step

Input table

Start with sales rows grouped by category.

Sales\text{Sales}
Salesorder_idcategoryamounto1book20o2book35o3pen5o4penNULLo5pen20

Group query

Group by category and count every row in each group.

GROUP BY category, COUNT(*)\text{GROUP BY category, COUNT(*)}
GROUP BY category countgroup_byarity 2 rows 2Salesarity 3 rows 5

Grouped output

The count includes the row whose amount is NULL.

row counts by category\text{row counts by category}
Grouped outputcategoryorder_countbook2pen3