使用下一个非空值bigquery填充空值

时间:2017-12-01 06:18:59

标签: google-bigquery

我有以下表格,其中包含来自BigQuery中GA的数据

userid  visitid purchase_date
GH8932  12345   2017-04-09
GH8932  12346   null
GH8932  12347   null
GH8932  12348   null
GH8932  12349   2017-05-30
GH8932  12350   null
GH8932  12351   null
GH8932  12352   2017-06-07
GH8932  12353   null
GH8932  12354   2017-06-30

我希望得到的表格是

userid  visitid purchase_date
GH8932  12345   2017-04-09
GH8932  12346   2017-05-30
GH8932  12347   2017-05-30
GH8932  12348   2017-05-30
GH8932  12349   2017-05-30
GH8932  12350   2017-06-07
GH8932  12351   2017-06-07
GH8932  12352   2017-06-07
GH8932  12353   2017-06-30
GH8932  12354   2017-06-30

我尝试了以下

select
a.userid,
a.visitid,
b.purchase_date
from x
left join
( 
select 
userid,
visitid,
purchase_data 
from x 
where purchase_date is not null) as b
on x.userid = b.userid
where x.visitid <= b.visitid

但是,这并没有提供我正在寻找的解决方案。

感谢BQ新秀的帮助

1 个答案:

答案 0 :(得分:3)

使用IGNORE NULLS和FIRST_VALUE在所需窗口中查找非空日期:

type Alphanumeric_Character is ('a', 'A',
                                'b', 'B',
                                'c', 'C',
                                ...
                                'z', 'Z',
                                '0', '1', '2', '3', '4',
                                '5', '6', '7', '8', '9');
相关问题