Skip site navigation (1) Skip section navigation (2)

Re: order by question

From: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>
To: Tony Liao <tonyliao(at)yuehetone(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: order by question
Date: 2009-06-19 14:49:19
Message-ID: dcc563d10906190749j31cd561en474bbe3b7096268e@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-admin
On Fri, Jun 19, 2009 at 3:50 AM, Tony Liao<tonyliao(at)yuehetone(dot)com> wrote:
> Hi,All
>        for example,I have a query as this
>          select id,product_id from table_name where product_id in
> (6,3,4,10,7) order by .....
>        the results I want to get as bellow:
> id................product_id......................
> 33...............6...................................
> 40...............6..................................
> 12...............3....................................
> 25...............4.................................
> 10...............4................................
> 17...............10.................................
> 43................7...................................
>           any Idea? thanks

I take it you want the set sorted by product_id order of 6,3,4,10 ???

order by
case when product_id = 6 then 1 when product_id=3 then 2 when
product_id=4 then 3 when product_id=10 then 4 else product_id+1000
end;

In response to

Responses

pgsql-admin by date

Next:From: Mary SippleDate: 2009-06-19 15:24:13
Subject: pg_dump exclude tables
Previous:From: Kenny W DrobnackDate: 2009-06-19 14:39:55
Subject: Re: order by question

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group