Skip to content

Instantly share code, notes, and snippets.

@evokateur
Last active June 9, 2026 20:42
Show Gist options
  • Select an option

  • Save evokateur/5d1b26e03c6f6ca3e5336c9910677769 to your computer and use it in GitHub Desktop.

Select an option

Save evokateur/5d1b26e03c6f6ca3e5336c9910677769 to your computer and use it in GitHub Desktop.
A MySQL query that generates integers 1 to 10000, for example (see below for months and years)
SELECT @row := @row + 1 as i FROM
(select 0 union all select 1 union all select 3 union all select 4 union all select 5 union all select 6 union all select 6 union all select 7 union all select 8 union all select 9) t,
(select 0 union all select 1 union all select 3 union all select 4 union all select 5 union all select 6 union all select 6 union all select 7 union all select 8 union all select 9) t2,
(select 0 union all select 1 union all select 3 union all select 4 union all select 5 union all select 6 union all select 6 union all select 7 union all select 8 union all select 9) t3,
(select 0 union all select 1 union all select 3 union all select 4 union all select 5 union all select 6 union all select 6 union all select 7 union all select 8 union all select 9) t4,
(SELECT @row:=0) t5;
@evokateur

Copy link
Copy Markdown
Author

You can put these together to generate a periods table for aggregate values from data where all periods aren't represented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment