pbPassingBI
/

What is the difference between WHERE and HAVING?

beginner
Answer

WHERE filters individual rows before any grouping happens. HAVING filters groups after aggregation.

Because of that, you cannot reference an aggregate in WHERE — it does not exist yet — and you generally should not put a row-level condition in HAVING, since filtering earlier means fewer rows reach the grouping step.

WHERE order_date >= '2024-01-01' then GROUP BY region then HAVING SUM(total) > 100000 is the idiomatic shape.

Related