sql question: min remapped value - Mailing list pgsql-sql

From Douglas Nichols
Subject sql question: min remapped value
Date
Msg-id 38348B20.6A4F8EF1@fhcrc.org
Whole thread Raw
Responses Re: [SQL] sql question: min remapped value  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
I am trying to remap a field find the row with the minimum value and
then keep the original value and the id number from that row something
like this:

mydata (id, field1)
field1 can = 0,1,2,3,4,5
but I reallt need them ordered like this (1=2, 0=2, 3=4, 4=5, 5=0)
once I find the lowest remapped value I need to know id & field1

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;

Any help is appreciated and thanks ahead!

Cheers, dn

Douglas Nichols                              dnichols@fhcrc.org
---------------------------------------------------------------
National Wilms Tumor Study Group                   206.667.4283
Seattle, WA


pgsql-sql by date:

Previous
From: wieck@debis.com (Jan Wieck)
Date:
Subject: Re: [SQL] Can't create an index on NUMERIC(x,y)
Next
From: Tom Lane
Date:
Subject: Re: [SQL] sql question: min remapped value