Re: Making NULL entries appear first when ORDER BY ASC

Поиск
Список
Период
Сортировка
От Andreas Joseph Krogh
Тема Re: Making NULL entries appear first when ORDER BY ASC
Дата
Msg-id 200502160939.27431.andreak@officenet.no
обсуждение исходный текст
Ответ на Re: Making NULL entries appear first when ORDER BY ASC  (Bruno Wolff III <bruno@wolff.to>)
Ответы Re: Making NULL entries appear first when ORDER BY ASC  (Thomas F.O'Connell <tfo@sitening.com>)
Список pgsql-sql
On Wednesday 16 February 2005 04:47, Bruno Wolff III wrote:
> > Now, as you see, touples with NULL in the "start_time"-field appear
> > "after" the others. I would like to make all entries where start_time IS
> > NULL apear *before* all the others. Any idea how to achieve this?
>
> SELECT start_date, start_time, end_time, title
> FROM onp_crm_activity_log
> WHERE start_date IS NOT NULL
> ORDER BY start_date ASC, start_time IS NOT NULL ASC, start_time ASC;
>
> This assumes you want the NULL start times first within a particular
> date. Otherwise change the order in the ORDER BY clause.

Thanks! This si, IMO, the cleanest solution as it doesn't involve any
COALESCE.

--
Andreas Joseph Krogh <andreak@officenet.no>
Senior Software Developer / Manager
gpg public_key: http://dev.officenet.no/~andreak/public_key.asc
------------------------+---------------------------------------------+
OfficeNet AS            | The most difficult thing in the world is to |
Hoffsveien 17           | know how to do a thing and to watch         |
PO. Box 425 Skøyen      | somebody else doing it wrong, without       |
0213 Oslo               | comment.                                    |
NORWAY                  |                                             |
Phone : +47 22 13 01 00 |                                             |
Direct: +47 22 13 10 03 |                                             |
Mobile: +47 909  56 963 |                                             |
------------------------+---------------------------------------------+

В списке pgsql-sql по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: UPDATE TRIGGER on view WAS: Re: Relation in tables
Следующее
От: Michael Fuhr
Дата:
Сообщение: Re: Trigger