Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 5483347586D for ; Mon, 1 Jul 2002 18:01:15 -0400 (EDT) Mailbox-Line: From nick@outerscape.net Mon Jul 1 18:01:15 2002 Received: from fc2.outerscape.net (fc2.outerscape.net [192.207.27.99]) by postgresql.org (Postfix) with ESMTP id 823A747583B for ; Mon, 1 Jul 2002 18:01:14 -0400 (EDT) Message-id: Date: Mon, 01 Jul 2002 17:00:18 -0500 Subject: CASE Select, referring to selected value To: pgsql-sql@postgresql.org From: "Nick Riemondi" MIME-Version: 1.0 Content-type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Status: No, hits=-1.9 required=5.0 tests=X_NOT_PRESENT version=2.30 X-Spam-Level: X-Archive-Number: 200207/14 X-Sequence-Number: 8393 Hi! I've got 2 date fields in table which constitute a term. On select I'm calculating that term, BUT I can't figure out how to refer to it in the sql - or if it's possible. I'd like to be able to use the case returned value for order, comparing, etc. Here's an example: select case when (current_date > available) then ((end_date - current_date) / 30) when (current_date < available) then ((end_date - available) / 30) end from listing This yields something along the line of: case ------ 2 39 11 64 ... which is great. Now, I'd like to be able to do this for example: select case when (current_date > available) then ((end_date - current_date) / 30) when (current_date < available) then ((end_date - available) / 30) end from listing where case > 4 which yields: ERROR: parser: parse error at or near ">" Does anyone know how I could accomplish this? Thanks in Advance! Nick