1

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

Manoj Agrawal
  • 775
  • 3
  • 8
  • 20
  • Is there a reason you cannot create `total_profit` using a derived table? – o-90 Jan 04 '17 at 18:24
  • Yeah, I have like 5 derived tables already and over 100 columns in select with 37 million rows to select. Trying to reduce the number of tables and sub-queries to optimize the processing time. – Manoj Agrawal Jan 04 '17 at 19:09

0 Answers0