Skip to content

Instantly share code, notes, and snippets.

@samyakrt
Created October 22, 2022 16:24
Show Gist options
  • Save samyakrt/5a79712e0e22d989a0a9c7c73dfc05ba to your computer and use it in GitHub Desktop.
Save samyakrt/5a79712e0e22d989a0a9c7c73dfc05ba to your computer and use it in GitHub Desktop.
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'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment