This post was kindly contributed by Heuristic Andrew - go there to comment and to read the full post. |
Netezza and SAS allow a query to reference a calculated column by name in the SELECT, WHERE, and ORDER BY clauses. Based on the DRY principle, this reduces code and makes code easier to read and maintain.
Some people call calculated columns derived or computed columns.
In Microsoft SQL Server, SQLite, and other RDBMSs you cannot exactly do this: a workaround is to reference a subquery or view. In Microsoft SQL Server, you can also define a computed column on a table.
Below is an example tested with Netezza 7.2. Notice height_m is used in the SELECT clause, and bmi is used in the WHERE and ORDER BY clauses.
This post was kindly contributed by Heuristic Andrew - go there to comment and to read the full post. |