| From: | Luca Ferrari <fluca1978(at)infinito(dot)it> |
|---|---|
| To: | Andreas <maps(dot)on(at)gmx(dot)net> |
| Cc: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: monthly statistics |
| Date: | 2013-07-24 11:27:39 |
| Message-ID: | CAKoxK+6c_KN2FbbukLr7SXANah38da437uNhkCkXaCsZh_tasg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
On Mon, Jul 8, 2013 at 2:18 PM, Andreas <maps(dot)on(at)gmx(dot)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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Gary Stainburn | 2013-07-25 17:45:51 | value from max row in group by |
| Previous Message | Bèrto ëd Sèra | 2013-07-24 10:12:35 | Re: Advice on key design |