SQLTeam.com | Weblogs | Forums

Explain of sintex

Hey everyone,
Would someone will be able to explain me 2 points:
Why HAVING must come after GROUP BY?
Why we do in HAVING, AVG(budget) and not HAVING avg_budget ?

Thanks a lot !!

SELECT release_year, AVG(budget) AS avg_budget, AVG(gross) AS avg_gross
FROM films
WHERE release_year > 1990
GROUP BY release_year
HAVING AVG(budget) > 6000000

HAVING works on aggregates which GROUP BY define.

SELECT is evaluated after HAVING:



thats the WAY they



if they say its CAT its CAT ....... if they says its 145 its 145