hive窗口函数

lead(expr [, offset] [, default]) OVER([partition_by_clause] order_by_clause)

This function returns the value of an expression using column values from a following row. You specify an integer offset, which designates a row position some number of rows after to the current row. Any column references in the expression argument refer to column values from that later row.


替换
hive窗口函数_第1张图片

lag(expr [, offset] [, default]) OVER ([partition_by_clause] order_by_clause)

This function returns the value of an expression using column values from a preceding row. You specify an integer offset, which designates a row position some number of rows previous to the current row. Any column references in the expression argument refer to column values from that prior row.

也就是说 lead就是下一个窗口,lag就是上一个窗口
比如说:

select order_original_id,
stage,
user_due_at_datetime,
lead(user_due_at_datetime,1)over(partition BY order_original_id
                                 ORDER BY stage) AS NEXT,
lag(user_due_at_datetime,1)over(partition BY order_original_id
                                ORDER BY stage) AS BEFORE
FROM access_views.o_loanpro_v_t_repayment_schedule
WHERE loantype IN (3,20)
  AND stage IN (2,3,4)
  AND is_deprecated=0
ORDER BY order_original_id,
         stage

hive窗口函数_第2张图片

你可能感兴趣的:(hive)