如何在配置单元中使用别名?

6jjcrrmo  于 2021-07-14  发布在  Spark
关注(0)|答案(1)|浏览(392)

我正在尝试使用窗口功能查找唯一的城市,我无法在此查询中使用别名

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:
lnvxswe2

lnvxswe21#

where子句中不能有窗口函数。将其放入子查询中,然后进行筛选:

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

相关问题