Last active
March 12, 2023 09:42
-
-
Save cabecada/c67442c051404d1ff5548b40a0270398 to your computer and use it in GitHub Desktop.
grouping by bucket size postgres
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
| https://stackoverflow.com/questions/22157718/postgres-group-by-timestamp-into-6-hourly-buckets | |
| select count(1), trunc(extract (minute from x) / 5) from generate_series(now() - '60 minute'::interval, now(), '1 minute'::interval) x group by trunc(extract (minute from x) / 5) order by 2 desc; | |
| count | trunc | |
| -------+------- | |
| 5 | 11 | |
| 5 | 10 | |
| 5 | 9 | |
| 5 | 8 | |
| 5 | 7 | |
| 5 | 6 | |
| 5 | 5 | |
| 5 | 4 | |
| 5 | 3 | |
| 6 | 2 | |
| 5 | 1 | |
| 5 | 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment