Example: Ordering on a Column Name Alias - Analytics Database - Teradata Vantage

SQL Data Manipulation Language

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2024-10-04
dita:mapPath
pon1628111750298.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
esx1472246586715
lifecycle
latest
Product Category
Teradata Vantageā„¢

Define a column named j in table t1.

The following statement returns an error because j is defined to be an alias for the expression SUM(t1.j). However, when it is used in the ORDER BY clause, the system resolves it to the column j and not the expression aliased by j:

     SELECT t1.i, SUM(t1.j) AS j, t1.k
     FROM t1
     GROUP BY 1,3
     ORDER BY j;

The following statement works because the column name alias jj is not the same as the column name j, and there is no column named jj in the table definition.

     SELECT t1.i, SUM(t1.j) AS jj, t1.k
     FROM t1
     GROUP BY 1,3
     ORDER BY jj;