Re: [SQL] sql question: min remapped value

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Douglas Nichols <dnichols(at)fhcrc(dot)org>
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] sql question: min remapped value
Date: 1999-11-19 00:43:53
Message-ID: 358.942972233@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Douglas Nichols <dnichols(at)fhcrc(dot)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

Browse pgsql-sql by date

  From Date Subject
Next Message Haris Susanto 1999-11-19 07:24:06 Backend message type 0x45 arrived while idle
Previous Message Douglas Nichols 1999-11-18 23:26:24 sql question: min remapped value