Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 87403475F28 for ; Wed, 6 Nov 2002 10:15:04 -0500 (EST) Received: from anchor-post-34.mail.demon.net (anchor-post-34.mail.demon.net [194.217.242.92]) by postgresql.org (Postfix) with ESMTP id 1341F475EF7 for ; Wed, 6 Nov 2002 10:15:01 -0500 (EST) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-34.mail.demon.net with esmtp (Exim 3.35 #1) id 189RtY-000Eoz-0Y; Wed, 06 Nov 2002 15:15:04 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id D87DE16432; Wed, 6 Nov 2002 15:11:14 +0000 (GMT) Received: from client.archonet.com (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with ESMTP id 2337315933; Wed, 6 Nov 2002 15:11:14 +0000 (GMT) Content-Type: text/plain; charset="iso-8859-2" From: Richard Huxton Organization: Archonet Ltd To: , "Postgresql Sql Group (E-mail)" Subject: Re: FW: query optimization question Date: Wed, 6 Nov 2002 15:11:22 +0000 User-Agent: KMail/1.4.3 References: <002601c2859d$0d825480$2766f30a@development.greatgulfhomes.com> In-Reply-To: <002601c2859d$0d825480$2766f30a@development.greatgulfhomes.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200211061511.22676.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/75 X-Sequence-Number: 10217 On Wednesday 06 Nov 2002 2:01 pm, terry@ashtonwoodshomes.com wrote: > However, for the total deficiencies I am then splitting up the total into > aging groups, eg <30, 30-60, 60-90, and >90 days old. The query for that > looks like the below. But before I paste it in, I would like to optimize > it, if I could do so with a group by clause I most certainly would, but I > don't see how I can BECAUSE OF THE AGING BREAKDOWN: [one sub-query per age-range] > AND dt.days_old_start_date < {d '2002-10-07'} > ) AS def_count_less_30, > AND dt.days_old_start_date >=3D {d '2002-10-07'} > AND dt.days_old_start_date < {d '2002-09-07'} > ) AS def_count_30_60, Could you not define a function age_range(date) to return the relevant rang= e=20 text, then group on that text? I've used that before. --=20 Richard Huxton