Re: Group by range in hour of day

Поиск
Список
Период
Сортировка
От Paul Jungwirth
Тема Re: Group by range in hour of day
Дата
Msg-id 5507564C.6070900@illuminatedcomputing.com
обсуждение исходный текст
Ответ на Group by range in hour of day  (Israel Brewster <israel@ravnalaska.net>)
Ответы Re: Group by range in hour of day  (Israel Brewster <israel@ravnalaska.net>)
Список pgsql-general
> I have a table with two timestamp columns for the start time and end
> time of each record (call them start and end).I'm trying to figure out
> if there is a way to group these records by "hour of day",

I think you can do this by selecting `FROM generate_series(0, 23) s(h)`
and then joining to your table based on `h BETWEEN start AND end`.

Whenever I need to write a time-series aggregate query I reach for
generate_series. Mostly that's so I have output rows even when COUNT(*)
would be 0, but here it also means that a row from your data can feed
into multiple output rows.

I could probably write this out in more detail if you like, but that's
the short version. :-)

Good luck!

Paul







В списке pgsql-general по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: Group by range in hour of day
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: Group by range in hour of day