All Forums Analytics
yunfeizhao 6 posts Joined 02/15
10 Feb 2015
How to use Column alias in Teradata

How to use Column alias in Teradata
My understanding is that we can use column alias in select, where, group, having,order by, and we can use it directly. Right?
Here is my example code below
Select 
sum(a) as asum,
asum+b as bsum 
from table
where bsum > 10
This code does not run as expected if my table has a column with the same name as the alias asum.
Can you please give some reading on the use of alias in Teradata? How to use alias and what are the rules.
Thanks
Yunfei
 

dnoeth 4628 posts Joined 11/04
11 Feb 2015

Using a column alias (outside of ORDER BY) is not supported by Standard SQL (the SELECT list is created after processing, WHERE/HAVING/QUALIFY, but before ORDER BY).
Teradata's parser follows a simple rule, search the list of columns first before you check the list of aliases. So when a column alias matches an existing column name the parser will never find the alias.
The rule of thumb is "never alias to an existing column name"

Dieter

yunfeizhao 6 posts Joined 02/15
12 Feb 2015

Thanks a lot

You must sign in to leave a comment.