Strictly speaking, and if I remember well, the SQL standard define HAVING
clause to be processed before the SELECT
clause. So, an alias defined in the SELECT, cannot be used in HAVING
clause.
See my answer in a related question: Using 'case expression column' in where clause for the order of proccessing a SELECT
statement, which is:
FROM -> WHERE -> GROUP BY -> HAVING -> SELECT -> ORDER BY
So, in most SQL incarnations, that query will yield an error. MySQL is one exception I know that allows this deviation from the standard (and where SELECT
aliases are allowed to be used in the GROUP BY
clause as well).
As @a_horse_with_no_name mentioned in comments, the query would fail in most SQL products for another reason, too: HAVING
without GROUP BY
means there is an aggregation over all the rows and thus only aggregate functions would be allowed in both the HAVING
and the SELECT
clauses.
After looking at the SAS SQL documentation and examples, it seems the query you posted above is valid in SAS SQL and executed as this (in standard SQL):
SELECT name, height * weight AS inchpounds
FROM sashelp.class
WHERE height * weight > 5000;
If I understand it correctly, you may also mix aggregate functions with non-aggregated columns, like this:
SELECT name, height,
MAX(height) AS max_height
FROM sashelp.class ;
which would be evaluated as (in standard SQL):
SELECT name, height,
MAX(height) OVER () AS max_height
FROM sashelp.class ;