From: Rodrigo De León <rdeleonp@gmail.com>
To: pgsql-sql@postgresql.org
Cc: Pablo Barrón <amentoraz@gmail.com>
Subject: Re: ordering by multiple columns
Date: Wed, 14 Mar 2007 11:14:49 -0500
Message-ID: <a55915760703140914q5883f01fud0572153e575285d@mail.gmail.com> (raw)
In-Reply-To: <d4d13b4c0703140850i4957116bw8a25255131a56346@mail.gmail.com>
References: <d4d13b4c0703140850i4957116bw8a25255131a56346@mail.gmail.com>
On 3/14/07, Pablo Barrón <amentoraz@gmail.com> wrote:
> Hi!
>
> I'm trying to order a list in which the first parameter to order is a
> specific field, and the second should vary depending on a specific
> condition. More explicit, I would like to do something like:
>
> - ORDER BY a.column1, [b.column2 if c.value != 19 || c.column2 if
> c.value==19]
>
> That is to say, use a column if a value on each row isn't 19, OR use a
> different column if it isn't. How could I solve this? I've got to have a
> global order over my query, so I cannot separate it into two queries, etc
> :-?
>
> Thank you!
SELECT (...)
ORDER BY a.column1, CASE
WHEN c.VALUE <> 19
THEN b.column2
ELSE c.column2
END;
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: rdeleonp@gmail.com, amentoraz@gmail.com
Subject: Re: ordering by multiple columns
In-Reply-To: <a55915760703140914q5883f01fud0572153e575285d@mail.gmail.com>
* 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