What is the difference between WHERE and HAVING?
EasyWHERE filters rows before grouping; HAVING filters groups after aggregation. That is why aggregates can appear in HAVING but not in WHERE.
SELECT customer_id, SUM(total) AS spent
FROM orders
WHERE status = 'completed' -- row filter, pre-aggregation
GROUP BY customer_id
HAVING SUM(total) >= 1000; -- group filter, post-aggregation
Anchor the answer in the logical evaluation order: FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY. WHERE cannot see aggregates because they do not exist yet when it runs.