pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedordering by multiple columns
3+ messages / 3 participants
[nested] [flat]
* ordering by multiple columns
@ 2007-03-14 15:50 Pablo Barrón <amentoraz@gmail.com>
2007-03-14 16:12 ` Re: ordering by multiple columns Andreas Kretschmer <akretschmer@spamfence.net>
2007-03-14 16:14 ` Re: ordering by multiple columns Rodrigo De León <rdeleonp@gmail.com>
0 siblings, 2 replies; 3+ messages in thread
From: Pablo Barrón @ 2007-03-14 15:50 UTC (permalink / raw)
To: pgsql-sql
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!
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: ordering by multiple columns
2007-03-14 15:50 ordering by multiple columns Pablo Barrón <amentoraz@gmail.com>
@ 2007-03-14 16:12 ` Andreas Kretschmer <akretschmer@spamfence.net>
1 sibling, 0 replies; 3+ messages in thread
From: Andreas Kretschmer @ 2007-03-14 16:12 UTC (permalink / raw)
To: pgsql-sql
Pablo Barrón <amentoraz@gmail.com> schrieb:
>
> 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
You can do something like this:
order by a.column1, case when c.value != 19 then b.column2 else c.column2 end;
*untested*, but the way is to use a case when <condition> then ... else
... end; - construct.
Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknow)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: ordering by multiple columns
2007-03-14 15:50 ordering by multiple columns Pablo Barrón <amentoraz@gmail.com>
@ 2007-03-14 16:14 ` Rodrigo De León <rdeleonp@gmail.com>
1 sibling, 0 replies; 3+ messages in thread
From: Rodrigo De León @ 2007-03-14 16:14 UTC (permalink / raw)
To: pgsql-sql; +Cc: Pablo Barrón <amentoraz@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;
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2007-03-14 16:14 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-03-14 15:50 ordering by multiple columns Pablo Barrón <amentoraz@gmail.com>
2007-03-14 16:12 ` Andreas Kretschmer <akretschmer@spamfence.net>
2007-03-14 16:14 ` Rodrigo De León <rdeleonp@gmail.com>
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