X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id E69E59FA319 for ; Wed, 28 Jun 2006 17:29:23 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 25519-08 for ; Wed, 28 Jun 2006 17:29:17 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from niflheim.msglab.com (unknown [195.245.173.24]) by postgresql.org (Postfix) with ESMTP id 0B9529FA506 for ; Wed, 28 Jun 2006 17:29:15 -0300 (ADT) Received: from [192.168.1.24] (m3tahome [85.138.142.221]) by niflheim.msglab.com (Postfix) with ESMTP id 628DF2E025; Wed, 28 Jun 2006 21:29:10 +0100 (WEST) Subject: Re: generate_series with left join From: "Pedro B." To: Aaron Bono Cc: pgsql-sql@postgresql.org In-Reply-To: References: <1151510424.28638.18.camel@m3ta.msglab.mine.nu> <1151522786.2238.46.camel@localhost.localdomain> Content-Type: text/plain Date: Wed, 28 Jun 2006 21:28:30 +0100 Message-Id: <1151526511.2238.52.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.6.2 Content-Transfer-Encoding: 7bit X-MsgLab-MailScanner-Information: Please contact the ISP for more information X-MsgLab-MailScanner: Found to be clean X-MsgLab-MailScanner-SpamCheck: not spam (whitelisted), SpamAssassin (score=0, required 5, autolearn=not spam) X-MsgLab-MailScanner-From: pedro.borracha@msglab.com X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/306 X-Sequence-Number: 25542 On Wed, 2006-06-28 at 15:16 -0500, Aaron Bono wrote: > This should work too: > > select > year_list.year, > one_list.one_count, > two_list.two_count > FROM ( > select years > from generate_series(2006,2009) as years > ) year_list > left outer join ( > select > date_part('year', one.date) as one_year, > count(one.*) as one_count > from mytable as one > where one.cause = 1 > group by > date_part('year', one.date) > ) one_list on (year_list.years = one_year) > left outer join ( > select > date_part('year', two.date) as two_year, > count(two.*) as two_count > from mytable as two > where two.cause = 2 > group by > date_part('year', two.date) > ) two_list on (year_list.years = two_year) > ; Aaron, I confess i will take some time to digest the amazing code you just sent, but in the meantime, let me tell you right away that both work just as i needed. I will stop pulling my hairs now. Thank you so much. \\pb -- This message has been scanned for viruses and dangerous content at MsgLab.com and is believed to be clean.