lead函数语法

h79rfbju  于 2021-06-03  发布在  Hadoop
关注(0)|答案(1)|浏览(377)

有没有什么方法可以把below lead函数转换成hive ql格式??

NVL(LEAD(START_DT) OVER (PARTITION BY EV_ID,AR_EV_RLTNSHP_TYPE_CD ORDER BY START_DT)-1,'2099-12-31') AS DERIVED_END_DT

pfb错误:
失败:parseexception行1:1599丢失)在“over”附近('在子查询源中,行1:1603丢失在'('附近')('在子查询源中,行1:1604不能通过子查询源中的'ev\u id'识别'分区'附近的输入

cs7cruho

cs7cruho1#

这在hivesql中很复杂,但是您可以使用 left join 和聚合:

select t.ev_id, t.ar_ev_rltnshp_type_cd, t.start_date,
       coalesce(min(tnext.start_dt) - 1, '2099-12-31') as derived_end_dt
from table t left join
     table tnext
     on t.ev_id = tnext.ev_id and t.ar_ev_rltnshp_type_cd = tnext.ar_ev_rltnshp_type_cd and
        tnext.start_date > t.start_date
group by t.ev_id, t.ar_ev_rltnshp_type_cd, t.start_date;

这就对 start_date 在一个特定的群体中是独一无二的,但它可能会为你的目的而工作。

相关问题