【问题标题】:Record count for day and next day from table从表中记录当天和第二天的计数
【发布时间】:2017-03-06 00:33:00
【问题描述】:

我正在尝试使用以下配置单元查询查找第 + 1 天的记录数。收到错误,因为我们有 hive 0.10 版本。

select 
lead(count(*)) over (order by day),
day 
from device_fact_kpis 
where day=20160301 group 
by day;

FAILED: ParseException line 1:27 缺少 FROM at '(' near '(' in 子查询源行 1:28 无法识别 'order' 'by' 附近的输入 子查询源中的“天”

有没有办法在不使用前导函数的情况下找到第二天的计数,因为 hive 0.10 没有前导函数。

【问题讨论】:

    标签: hadoop hive


    【解决方案1】:

    您的查询无论如何都不起作用,因为您需要在按天过滤之前执行lead()

    在任何情况下,您都可以使用 CTE 和 join

    with t as (
          select day, count(*) as cnt
          from table t
          group by day
         )
    select day, cnt, tnext.cnt as next_cnt
    from t left join
         t tnext
         on tnext.day = date_add(t.day, 1);
    

    编辑:

    没有CTE的版本很相似:

    select day, cnt, tnext.cnt as next_cnt
    from (select day, count(*) as cnt
          from table t
          group by day
         ) t left join
         (select day, count(*) as cnt
          from table t
          group by day
         ) tnext
         on tnext.day = date_add(t.day, 1);
    

    【讨论】:

    • 感谢您的回复,使用此查询配置单元时出现以下错误> with t as (> select day, count(*) as cnt > from fact_vreclass_tickets t > where day=20160301 > group by day > ) > select day, cnt, tnext.cnt as next_cnt > from t left join > t tnext > on tnext.day = date_add(t.day, 1);失败:ParseException line 1:0 无法识别“with”“t”“as”附近的输入
    • 喂。你的版本甚至不支持 CTE?你可以用两个子查询做同样的事情。
    • Hive 0.11 中引入了 Windows 函数,而 Hive 0.13 中引入了 CTE。
    • 请在不使用 windows 功能和 CTE 的情况下提出解决此问题的方法,谢谢
    猜你喜欢
    • 2020-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多