lag
https://spark.apache.org/docs/latest/api/sql/#lag
lag(input[, offset[, default]]) OVER (PARTITION BY a ORDER BY b)
input - 求lag的目标字段
offset - lag步数
default - 空值用什么填充
select *,
lag(`fa_adjust`,-2, 0) over (partition by (`stock_id`, `sku`) order by `date` desc) `lag1_fa`,
lag(`fa_adjust`,-3, 0) over (partition by (`stock_id`, `sku`) order by `date` desc) `lag2_fa`,
lag(`fa_adjust`,-4, 0) over (partition by (`stock_id`, `sku`) order by `date` desc) `lag3_fa`
from input1
标签:sku,函数,lag,fa,sql,date,id
From: https://www.cnblogs.com/tian1022/p/17164958.html