pg.ddx.io pgsql-php@postgresql.org mailing list archivehelp / color / mirror / Atom feed
From: Greg Stark <gsstark@mit.edu>
To: pgsql-general@postgresql.org
Subject: Re: Reordering results for a report
Date: 13 Dec 2003 21:39:08 -0500
Message-ID: <87u144w2b7.fsf@stark.dyndns.tv> (raw)
In-Reply-To: <3FDA0AE7.60200@tesseract.net>
References: <3FDA0AE7.60200@tesseract.net>
Nathaniel Price <nprice@tesseract.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
view thread (11+ messages) latest in thread
Message-ID: <87u144w2b7.fsf@stark.dyndns.tv> Permalink: ../87u144w2b7.fsf@stark.dyndns.tv/ Also on: postgresql.org/message-id/87u144w2b7.fsf@stark.dyndns.tv ·
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-php@postgresql.org Cc: gsstark@mit.edu, pgsql-general@postgresql.org Subject: Re: Reordering results for a report In-Reply-To: <87u144w2b7.fsf@stark.dyndns.tv> References: <3FDA0AE7.60200@tesseract.net> <87u144w2b7.fsf@stark.dyndns.tv> * 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