Filter rows, then filter groups
“Paid orders” is a row condition; “customers with a large order total” is a group condition. Place both at the right stage so filtering does not accidentally change the total being tested.
WHERE filters rows before grouping; HAVING filters groups after their aggregates are calculated.
- HAVING
- A condition on groups after aggregation, such as a threshold on SUM or COUNT.