HAVING filters grouped rows after COUNT(*) has been computed.

highlighted = computed this step

Input table

Start with the same sales rows used for grouping.

Sales\text{Sales}
Salesorder_idcategoryamounto1book20o2book35o3pen5o4penNULLo5pen20

Group query

Group by category, count every row, then apply HAVING to the count.

GROUP BY category HAVING COUNT(*)\text{GROUP BY category HAVING COUNT(*)}
GROUP BY category HAVING count thresholdgroup by havingarity 2 rows 1Salesarity 3 rows 5

Grouped output

Only the category whose count is above the threshold remains.

groups after HAVING\text{groups after HAVING}
Grouped outputcategoryorder_countpen3