Last active
December 22, 2021 23:38
-
-
Save hoehrmann/b90fd8baa9a782ee952a16355fe8fb9a to your computer and use it in GitHub Desktop.
view_every_hour_past_six_months.sql
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
DROP VIEW IF EXISTS view_every_hour_past_six_months; | |
CREATE VIEW view_every_hour_past_six_months AS | |
WITH RECURSIVE | |
bounds AS ( | |
SELECT | |
strftime('%s', 'now', 'start of day', '-6 month') AS lower, | |
strftime('%s', 'now', 'start of day', '+1 day') AS upper | |
), | |
samples AS ( | |
SELECT lower AS sample FROM bounds | |
UNION | |
SELECT | |
strftime('%s', sample, 'unixepoch', '+1 hour') AS sample | |
FROM | |
samples | |
INNER JOIN bounds | |
WHERE | |
strftime('%s', sample, 'unixepoch', '+1 hour') < bounds.upper | |
) | |
SELECT | |
sample AS unixepoch, | |
strftime('%Y-%m-%dT%H:%M:%S', sample, 'unixepoch') AS iso | |
FROM | |
samples |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment