Created
February 24, 2014 12:27
-
-
Save chanmix51/9187504 to your computer and use it in GitHub Desktop.
statistic over time ranges
This file contains hidden or 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
WITH | |
timerange (ts) AS (SELECT generate_series(date_trunc('hour', min(collected_at)), date_trunc('hour', max(collected_at)) + '1 day'::interval, '1 hour'::interval) FROM statistic) | |
SELECT | |
ts, | |
count(stat), | |
stddev(stat), | |
avg(stat) | |
FROM | |
timerange t | |
LEFT JOIN statistic s ON s.collected_at <@ tsrange(t.ts, t.ts + '1 hour'::interval, '[)') | |
GROUP BY 1 | |
ORDER BY 1 ASC | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment