Re: DISTINCT ... ORDER BY

Поиск
Список
Период
Сортировка
От Nabil Sayegh
Тема Re: DISTINCT ... ORDER BY
Дата
Msg-id 3FA92AB3.2080509@e-trolley.de
обсуждение исходный текст
Ответ на Re: DISTINCT ... ORDER BY  (Bruno Wolff III <bruno@wolff.to>)
Ответы Re: DISTINCT ... ORDER BY  (Bruno Wolff III <bruno@wolff.to>)
Список pgsql-novice
Bruno Wolff III wrote:

> You can use a distinct on with order by clause as a subselect to eliminate
> the records you don't want. Then you can extract col3 from this subselect
> and order by the original sort order (instead of col3 first) to get the
> desired records in the desired order.
>
> It would look something like:
> select col3 from
>   (select distinct on (col3) * from tablename order by col1, col2, col3, col4)
>   order by col1, col2, col3, col4;

Unfortunately I need to ORDER BY expression, not plain columns.

SELECT DISTINCT ON (col_1) col_1 FROM tab ORDER BY col_2='foo' DESC, col_1='bar' DESC, col_3='blah' DESC;

fails with:

ERROR:  SELECT DISTINCT ON expressions must match initial ORDER BY expressions

:(

--
  e-Trolley Sayegh & John, Nabil Sayegh
  Tel.: 0700 etrolley /// 0700 38765539
  Fax.: +49 69 8299381-8
  PGP : http://www.e-trolley.de


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

Предыдущее
От: John Siggins
Дата:
Сообщение: Re: selecting rows based on unique fields in a column
Следующее
От: Nabil Sayegh
Дата:
Сообщение: Re: DISTINCT ... ORDER BY