一、背景
爬虫或业务场景运行中经常会出现丢数据的情况,可能随机丢一分钟,或者丢几十分钟,完全没有规律,如果想用上一个有效值来补全的话单纯用lag函数无法实现
二、测试数据准备
create table...string,
times bigint,
cnt bigint
)comment '测试'
stored as textfile;
insert into test values('a',1,null...insert into test values('a',2,10);
insert into test values('a',3,20);
insert into test values('a',4,null...,t1.times
,t1.cnt as ori_cnt --原始值
,nvl(t2.cnt,0) as cnt --补全后值
from (...,(t1.times-t1.rank1),t1.times)=t2.times;
可以看到为空的数据都以补全了,首条记录置为0