Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 1FA90475C8F for ; Thu, 20 Jun 2002 21:06:51 -0400 (EDT) Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (Postfix) with ESMTP id 6360E476762 for ; Thu, 20 Jun 2002 20:02:04 -0400 (EDT) Received: from [66.219.92.2] (HELO chocolate-mousse) by davinci.ethosmedia.com (CommuniGate Pro SMTP 3.5.9) with ESMTP id 1551207; Thu, 20 Jun 2002 17:02:06 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: Michael Agbaglo , pgsql-sql@postgresql.org Subject: Re: how to sort a birthday list ? Date: Thu, 20 Jun 2002 17:03:52 -0700 X-Mailer: KMail [version 1.4] References: <3D122508.70104@shifted-bytes.de> In-Reply-To: <3D122508.70104@shifted-bytes.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200206201703.52435.josh@agliodbs.com> X-Archive-Number: 200206/282 X-Sequence-Number: 8247 Michael, > SELECT * > FROM Persons > WHERE EXTRACT( YEAR FROM AGE(dateofbirth) ) < EXTRACT( YEAR FROM AGE(=20 > CURRENT_DATE+60, dateofbirth ) ) >=20 > ... but how do I sort the list ? Easy: SELECT person_name, person_department, EXTRACT( YEAR FROM AGE(dateofbirth)= )=20 as their_age FROM Persons WHERE EXTRACT( YEAR FROM AGE(dateofbirth) ) < EXTRACT( YEAR FROM AGE(=20 CURRENT_DATE+60, dateofbirth ) ) ORDER BY their_age, person_name As an example. --=20 -Josh Berkus