0
What difference between HAVING, WHERE?
2 odpowiedzi
+ 7
"The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions."
Quoted from:
https://www.w3schools.com/sql/sql_having.asp
+ 3
You use WHERE to filter your initial table, so that only the filtered records are aggregated.
You use HAVING clause after GROUP BY, to further filter the aggregated results.
Example:
SELECT job, AVG(age)
FROM employees
WHERE department = 'IT'
GROUP BY job
HAVING AVG(age) > 30
This would first find the people who work in IT department, calculate their average age in each job, then give you the result for those jobs only where the calculation is over 30.