--oracle,hive的first_value和last_value函数
--内部分组后取第一条和最后一条(不是记录默认顺序的最后一条,而是排序后的最后一条)
--last列等同于last1列
--最后结果默认会以prdu_num的asc排序
查询:
select
first_value(cust_actnum) over (partition by prdu_num order by cust_actnum rows between unbounded preceding and unbounded following) first
,first_value(cust_actnum) over (partition by prdu_num) first1
,last_value(cust_actnum) over (partition by prdu_num order by cust_actnum rows between unbounded preceding and unbounded following) last
--,last_value(cust_actnum) over (partition by prdu_num order by cust_actnum) last22
,last_value(cust_actnum) over (partition by prdu_num) last1
,a.*
from upsrdp.TABLE_DUZHAOZHAO a
结果:
2021-12-23