【问题标题】:How to use an alias in Hive?如何在 Hive 中使用别名?
【发布时间】:2021-07-10 12:20:14
【问题描述】:

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

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:

【问题讨论】:

    标签: sql apache-spark hive


    【解决方案1】:

    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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-16
      • 2018-11-13
      • 2012-08-05
      • 2020-04-17
      • 1970-01-01
      • 1970-01-01
      • 2019-07-26
      相关资源
      最近更新 更多