有什么方法可以将下面的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错误:
最佳答案
在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
在给定组中是唯一的进行了某些假设,但可能会满足您的目的。关于sql - HIVE-QL中的LEAD函数语法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24777432/