Re: order by question

From: Tony Liao <tonyliao(at)yuehetone(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: order by question
Date: 2009-06-20 01:32:36
Message-ID: 8f750b7c0906191832y42889854kc66a618262eb2d27@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Thanks,All, To Tino,I want to order by IN condition "(6,3,4,10,7)".
To Sergio,my answer is "Yes".
To Kenny,I think this is not the result I want to get.
To Scott,In database,there are thousands of products.the select
query is generated by application,and it is not sure how many product_id
in condition,maybe the next query would be .........product_id in
(4,26,7,8,9,23,27,54)
Maybe,temp table is a solution,but that would be performance issue.

thanks

2009/6/19 Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>

> 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;
>

--
Tony Liao

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Scott Marlowe 2009-06-20 01:46:46 Re: order by question
Previous Message Alvaro Herrera 2009-06-19 17:27:53 Re: WAL archiving and backup TAR