From: | Greg Stark <gsstark(at)mit(dot)edu> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Reordering results for a report |
Date: | 2003-12-14 02:39:08 |
Message-ID: | 87u144w2b7.fsf@stark.dyndns.tv |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-php |
Nathaniel Price <nprice(at)tesseract(dot)net> writes:
> I'm new to this list, so I'm not sure if this is the right place to post this.
> If not, please direct me to where it would be better to post it.
>
> Anyway, I'm creating a report generation tool of sorts in PHP for a database.
> As part of this report generation tool, I'd like to allow the user to reorder
> these results arbitrarily. In other words:
>
> id | offer
> ---+------------
> 1 | Offer 1
> 2 | Offer 2
> 3 | Offer 3
>
> could become
>
> id | offer
> ---+------------
> 3 | Offer 3
> 1 | Offer 1
> 2 | Offer 2
You could do something like
select id,offer
from tab
order by case when id = 3 then 1 when id = 1 then 2 when id = 2 then 3 end
But a) if there are thousands of records you're going to have rather a huge
query and b) where are you going to store this ordering?
--
greg
From | Date | Subject | |
---|---|---|---|
Next Message | Greg Stark | 2003-12-14 02:44:23 | Re: tablespaces in 7.5? |
Previous Message | Bruno Wolff III | 2003-12-14 00:37:06 | Re: Delete all records NOT referenced by Foreign Keys |
From | Date | Subject | |
---|---|---|---|
Next Message | Tino Wildenhain | 2003-12-15 09:02:18 | Re: [GENERAL] Reordering results for a report |
Previous Message | Bruno Wolff III | 2003-12-13 23:47:32 | Re: Reordering results for a report |