| From: | Andreas Kretschmer <akretschmer(at)spamfence(dot)net> | 
|---|---|
| To: | pgsql-sql(at)postgresql(dot)org | 
| Subject: | Re: ordering by multiple columns | 
| Date: | 2007-03-14 16:12:35 | 
| Message-ID: | 20070314161235.GB3930@KanotixBox | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-sql | 
Pablo Barrón <amentoraz(at)gmail(dot)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°
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Rodrigo De León | 2007-03-14 16:14:49 | Re: ordering by multiple columns | 
| Previous Message | Andrew Sullivan | 2007-03-14 15:58:44 | Re: import CSV file |