1> WHERE Clause
- Filters rows before grouping.
- Works with non-aggregate conditions (like simple comparisons on columns).
2> HAVING Clause
Filters groups after aggregation.
Works with aggregate functions (SUM, AVG, MAX, MIN, COUNT).
Eg : SELECT employee, SUM(bonus) FROM emp_bonus
GROUP BY employee HAVING SUM(bonus) > 5000;
💡 In Short :
WHERE = "Which rows should I include in the group?"
HAVING = "Which groups should I keep after aggregation?"
Comments
Post a Comment