How to use Column alias in Teradata

Analytics
Enthusiast

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

2 REPLIES
Senior Apprentice

Re: How to use Column alias in Teradata

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"

Enthusiast

Re: How to use Column alias in Teradata

Thanks a lot