On Mon, Jul 8, 2013 at 2:18 PM, Andreas <maps...@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 -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql