pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Douglas Nichols <dnichols@fhcrc.org>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] sql question: min remapped value
Date: Thu, 18 Nov 1999 19:43:53 -0500
Message-ID: <358.942972233@sss.pgh.pa.us> (raw)
In-Reply-To: <38348B20.6A4F8EF1@fhcrc.org>

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



view thread (2+ messages)

Message-ID: <358.942972233@sss.pgh.pa.us>
Permalink:  ../358.942972233@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/358.942972233@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, dnichols@fhcrc.org
  Subject: Re: [SQL] sql question: min remapped value
  In-Reply-To: <358.942972233@sss.pgh.pa.us>
  References: <38348B20.6A4F8EF1@fhcrc.org> <358.942972233@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox