The HAVING clause

I need some clarity.

When invoke HAVING as follows:

SELECT location, ROUND(AVG(employees)) AS 'No. employees'
FROM startups
GROUP BY location
HAVING ROUND(AVG(employees)) > 500
ORDER BY 2 DESC;

I get the desired results.

But when I invoke HAVING using column referencing like so:

SELECT location, ROUND(AVG(employees)) AS 'No. employees'
FROM startups
GROUP BY location
HAVING 2 > 500
ORDER BY 2 DESC;

I don’t get any results.

What rule am I breaking?

2 Likes

As far as I’m aware HAVING can not work with column numbers.

2 Likes

That’s what I suspected, thanks

2 Likes