Skip to content

Instantly share code, notes, and snippets.

@samyakrt
samyakrt / time-series.sql
Created October 22, 2022 16:24
generate time series between specified months
WITH RECURSIVE dates_without_gaps(month) AS (
SELECT
DATE_SUB('2022-10-15', INTERVAL 1 YEAR) as month
UNION ALL
SELECT
DATE_ADD(month, INTERVAL 1 MONTH) as month
FROM
dates_without_gaps
WHERE
month < '2022-10-15'