在BigQuery中生成连续的时间结果集

参考链接:

  1. 生成数组的方法: https://cloud.google.com/bigquery/docs/reference/standard-sql/array_functions
  2. cross join : https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax

在BigQuery中提供了生成连续时间数组的方法GENERATE_DATE_ARRAY,该方法返回的是一个一行一列的数组

select GENERATE_DATE_ARRAY(date(2020,01,01),date(2022,01,01),interval 1 month) as datearray

当我们想要使用它的时候,通常需要将它展开,这个时候就轮到cross join 出场了,将原本一行一列的数组展开成多行一列的结果集

with dateArrayList as (select GENERATE_DATE_ARRAY(date(2020,01,01),date(2022,01,01),interval 1 month) as dateArray)
select dateArray from dateArrayList
cross join dateArrayList.dateArray

 

posted @ 2020-10-21 23:22  仲夏.net  阅读(288)  评论(0编辑  收藏  举报