How can I use column alias in later part of a hive query

972 views Asked by At

Is there a way to use column alias declared earlier later in the query? I have something like this

select item_id, 
       sum(sales) as total_sales,
       sum(cost) as total_cost
       total_sales - total_cost as total_profit
       from table A
       group by item_id,total_profit;

I tried using

SET hive.groupby.orderby.position.alias=true;

but doesn't work.

I know I can do this in Teradata so I am hoping there must be some way to do this in Hive as well.

thanks,

Manoj Agrawal

0

There are 0 answers