in the project at the end of the aggregate functions unit and one of the exercises resulted in the following code:
SELECT location, AVG(employees)
FROM startups
GROUP BY location
HAVING AVG(employees) > 500;
I can replace the column reference in the “group by” line, but not in the “having” line.
This works:
SELECT location, AVG(employees)
FROM startups
GROUP BY 1
HAVING AVG(employees) > 500;
This does not work:
SELECT location, AVG(employees)
FROM startups
GROUP BY 1
HAVING 2 > 500;
Why?