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.

Revisions

  1. samyakrt created this gist Oct 22, 2022.
    11 changes: 11 additions & 0 deletions time-series.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    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'
    )