you put a conditional clause in the order by statement, either by referencing a column that is populated conditionally, like this
select A, when B < C Then B else C end as condColumn, B, C, D
from ...
where ...
order by 1,2, 5
or
select A, when B < C Then B else C end as condColumn, B, C, D
from ...
where ...
order by A,condColumn, D
or you can just put the conditional statement in the order by clause (which surprised me, but I tested it)
select A, B, C, D
from ...
where ...
order by A,when B < C then B else C end, D
On Wed, Sep 12, 2012 at 2:44 PM, Rodrigo Rosenfeld Rosas
<rr.rosas@gmail.com> wrote:
This is my first message in this list :)
I need to be able to sort a query by column A, then B or C (which one
is smaller, both are of the same type and table but on different left
joins) and then by D.
How can I do that?
Thanks in advance,
Rodrigo.
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql