如何在BigQuery Standard SQL中生成系列

时间:2016-08-10 22:40:34

标签: google-bigquery

我需要在每行中生成 600个连续数字(从51开始)的表格 我如何使用BigQuery Standard SQL执行此操作?

2 个答案:

答案 0 :(得分:10)

在标准SQL中尝试GENERATE_ARRAY

SELECT num FROM UNNEST(GENERATE_ARRAY(51, 650)) AS num;

答案 1 :(得分:3)

BigQuery标准SQL

SELECT 50 + ROW_NUMBER() OVER() AS num
FROM UNNEST((SELECT SPLIT(FORMAT("%600s", ""),'') AS h FROM (SELECT NULL))) AS pos
ORDER BY num

BigQuery Legacy SQL

SELECT 50 + pos AS pos FROM (
  SELECT ROW_NUMBER() OVER() AS pos, * 
  FROM (FLATTEN((SELECT SPLIT(RPAD('', 600, '.'),'') AS h FROM (SELECT NULL)), h))
) WHERE pos BETWEEN 1 AND 600

从那里你可以调整逻辑例如以获得连续的日期和其他序列