Re: ORDER BY

Поиск
Список
Период
Сортировка
От Harald Fuchs
Тема Re: ORDER BY
Дата
Msg-id pupsbn3dy8.fsf@srv.protecting.net
обсуждение исходный текст
Ответ на ORDER BY  ("MicroUser" <a.shafar@gmail.com>)
Ответы Re: ORDER BY  ("Gurjeet Singh" <singh.gurjeet@gmail.com>)
Список pgsql-general
In article <DFDFB8FE-1787-4508-97C4-5FD12357936A@purefiction.net>,
Alexander Staubo <alex@purefiction.net> writes:

> On Nov 14, 2006, at 23:03 , MicroUser wrote:
>> I need sorted result but the way like this:
>>
>> 0 | Anna
>> 3 | Fernando
>> 2 | Link
>> 1 | Other
>>
>> Record '1 | Other' must by at the end of query result.

> It's not apparent from your example that you want something other
> than a purely lexicographic sort order (after all, "Other" comes
> after "Link", "Fernando" and "Anna", so "order by name" already gets
> you what you want), but I assume that's what you mean.

> If your table is sufficiently small, and the complexity of the actual
> query sufficiently low, prepending an expression sort key might
> suffice:

>    select * from foo
>    order by (case name when 'Other' then 1 else 0 end), name

Why so complicated?

SELECT whatever FROM foo ORDER BY name = 'Other', name

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

Предыдущее
От: bayerj@in.tum.de
Дата:
Сообщение: Postgres misses readline
Следующее
От: "sumit kumar"
Дата:
Сообщение: Queries those voilate Cost domination Principle