Re: monthly statistics - Mailing list pgsql-sql

From Luca Ferrari
Subject Re: monthly statistics
Date
Msg-id CAKoxK+6c_KN2FbbukLr7SXANah38da437uNhkCkXaCsZh_tasg@mail.gmail.com
Whole thread Raw
In response to monthly statistics  (Andreas <maps.on@gmx.net>)
List 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 by date:

Previous
From: Bèrto ëd Sèra
Date:
Subject: Re: Advice on key design
Next
From: Anton Gavazuk
Date:
Subject: Re: Advice on key design