Re: monthly statistics

Поиск
Список
Период
Сортировка
От Luca Ferrari
Тема Re: monthly statistics
Дата
Msg-id CAKoxK+6c_KN2FbbukLr7SXANah38da437uNhkCkXaCsZh_tasg@mail.gmail.com
обсуждение исходный текст
Ответ на monthly statistics  (Andreas <maps.on@gmx.net>)
Список pgsql-sql
On Mon, Jul 8, 2013 at 2:18 PM, Andreas <maps.on@gmx.net> wrote:

> How could I combine those 2 queries so that the date in query 1 would be
> replaced dynamically with the result of the series?
>


Surely I'm missing something, but maybe this is something to work on:

WITH
RECURSIVE months(number) AS ( SELECT 1 UNION SELECT number + 1 FROM
months WHERE number < 12 )
SELECT m.number, s.id, s.name, count( h.state_id )
FROM state s JOIN history h ON s.id = h.state_id
JOIN months m ON m.number = date_part( 'month', h.ts )


Luca



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

Предыдущее
От: Bèrto ëd Sèra
Дата:
Сообщение: Re: Advice on key design
Следующее
От: Anton Gavazuk
Дата:
Сообщение: Re: Advice on key design