Re: CASE Select, referring to selected value

From: "Nick Riemondi" <nick(at)outerscape(dot)net>
To: achill(at)matrix(dot)gatewaynet(dot)com
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: CASE Select, referring to selected value
Date: 2002-07-02 14:30:19
Message-ID: fc.009863ef000899b8009863ef00088e10.899c1@fc2.outerscape.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I finally thought to try this about an hour after posting. Doh! Works
perfectly.
Thanks!

achill(at)matrix(dot)gatewaynet(dot)com writes:
>On Mon, 1 Jul 2002, Nick Riemondi wrote:
>
>Just rewrite your case statement in the where clause.
>
>> 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
>>
>>
>>
>>
>>
>> ---------------------------(end of broadcast)---------------------------
>> TIP 3: if posting/reading through Usenet, please send an appropriate
>> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
>> message can get through to the mailing list cleanly
>>
>>
>
>--
>Achilleus Mantzios
>S/W Engineer
>IT dept
>Dynacom Tankers Mngmt
>tel: +30-10-8981112
>fax: +30-10-8981877
>email: achill(at)matrix(dot)gatewaynet(dot)com
> mantzios(at)softlab(dot)ece(dot)ntua(dot)gr
>

-=-=-=-=-=-=-=-
Nick Riemondi
OuterScape
nick(at)outerscape(dot)net
451-0535

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Ahti Legonkov 2002-07-02 15:46:59 Why doesn't it use indexes?
Previous Message Christopher Kings-Lynne 2002-07-02 13:57:09 Re: CASE Select, referring to selected value