Skip to content
Advertisement

How to use an alias in Hive?

I am trying to find unique cities using the window function, I am not able to use an alias in this query

select branch,city,row_number() over(partition by city order by branch) as row_number from 
sales_report where row_number=1;

Error in query: cannot resolve '`row_number`' given input columns:

Advertisement

Answer

You cannot have a window function in the where clause. Put it in a subquery and do the filter afterwards:

select * from
(
select branch,city,row_number() over(partition by city order by branch) as rn 
from sales_report 
) as t 
where rn = 1;
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement