Re: [SQL] sql question: min remapped value - Mailing list pgsql-sql

From Tom Lane
Subject Re: [SQL] sql question: min remapped value
Date
Msg-id 358.942972233@sss.pgh.pa.us
Whole thread Raw
In response to sql question: min remapped value  (Douglas Nichols <dnichols@fhcrc.org>)
List pgsql-sql
Douglas Nichols <dnichols@fhcrc.org> writes:
> I was looking at something like
> select id, field1, min(decode(field1,1,1,0,2,3,4,4,5,0)) as flag
>   from mydata
>   group by id;

Postgres doesn't have DECODE (nor is it in the SQL standard), but
you can get the effect you want with a CASE expression.  Note that
CASE is rather buggy in pre-6.5.2 releases, so update if you haven't
lately.

PS: you won't be able to access field1 outside the MIN() if you have
"group by id" as shown.
        regards, tom lane


pgsql-sql by date:

Previous
From: Douglas Nichols
Date:
Subject: sql question: min remapped value
Next
From: Haris Susanto
Date:
Subject: Backend message type 0x45 arrived while idle