I have done some tests with Having In Google BigQuery and found out: I can use the column alias in HAVING without error
SELECT
geoNetwork_city as total_CITY,
sum( totals_transactions) as total_transcations,
FROM
tablename
GROUP BY
geoNetwork_city
HAVING total_CITY not like 'NEW YORK'
ORDER by distinct_visitors desc
But isn't HAVING clause got executed before SELECT clause, which the alias hasn't formed yet? Why will we not receive any error?
Also, can we replace where with Having for non-aggregation function?
SELECT
geoNetwork_city as total_CITY
FROM
tablename
HAVING
total_CITY not like 'NEW YORK'
2 How about alias using in MS SQL Server? I found in MS SQL, the only place (I'm aware of) that you can reference aliases is in the ORDER BY clause. Is this correct?