Created
July 30, 2019 02:40
-
-
Save terashim/8b8613ebbfb4abed2732c5c020e63fcd to your computer and use it in GitHub Desktop.
BigQueryで連番の日付を生成する例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- BigQueryで連番の日付を生成する例 | |
-- Standard SQL を使用 | |
-- 2019-04-01 から 2020-03-31 まで | |
SELECT | |
DATE_ADD(start_date.start_date, INTERVAL n.n DAY) AS date | |
FROM ( | |
SELECT | |
DATE('2019-04-01') AS start_date) AS start_date | |
LEFT JOIN ( | |
SELECT | |
n | |
FROM | |
UNNEST(GENERATE_ARRAY(0, DATE_DIFF( DATE('2020-03-31'), DATE('2019-04-01'), DAY))) AS n | |
ORDER BY | |
n) AS n | |
ON | |
1=1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
GENERATE_DATE_ARRAY で良かったorz