Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id B775C475F34 for ; Wed, 6 Nov 2002 10:58:32 -0500 (EST) Received: from fzkmail2.fzk.de (fzkmail2.fzk.de [141.52.27.52]) by postgresql.org (Postfix) with SMTP id 89877475F2B for ; Wed, 6 Nov 2002 10:58:31 -0500 (EST) Received: FROM resy5.fzk.de BY fzkmail2.fzk.de ; Wed Nov 06 16:58:32 2002 +0100 Received: œby rodos.fzk.de with ESMTP (8.8.6 (PHNE_17135)/8.7.1) id QAA05171; Wed, 6 Nov 2002 16:58:32 +0100 (MET) Message-ID: <3DC93C27.5927F7D6@rodos.fzk.de> Date: Wed, 06 Nov 2002 16:58:31 +0100 From: Christoph Haller X-Mailer: Mozilla 4.06 [en] (X11; I; HP-UX B.10.20 9000/780) MIME-Version: 1.0 To: terry@greatgulfhomes.com Cc: pgsql-sql@postgresql.org Subject: Re: query optimization question Content-Type: text/plain; charset=iso-8859-2 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/76 X-Sequence-Number: 10218 Now that I've given your problem more thoughts (and searched for similar stuff), I think what you need is generating a cross table resp. pivot table. Related to this, I am thinking of a query using Conditional Expressions like COUNT ( CASE WHEN ... THEN 1 ELSE NULL) in order to use GROUP BY. Together with Richard's idea of using a function age_range(date) it seems realizable. I'm not yet ready to make a more detailed proposal, but you might want to think about it in the meantime, too. Regards, Christoph