Reputation: 55
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:
Upvotes: 0
Views: 627
Reputation: 42332
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;
Upvotes: 2