Re: Special grouping on sorted data.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Special grouping on sorted data.
Дата
Msg-id 17094.1222223123@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Special grouping on sorted data.  (Nicolas Beuzeboc <nicolasb@norchemlab.com>)
Список pgsql-sql
Nicolas Beuzeboc <nicolasb@norchemlab.com> writes:
> I which distinct on was more flexible, it's not happy when the order by 
> set is different than the distinct on set.
> I would like to be able to write select distinct on (b,n) b,n,stamp from 
> table where ... order by stamp;

Well, no, because it's defined to use the ORDER BY order to determine
which row is "first" within each DISTINCT ON group.

There is an easy workaround for this, which is to sort the rows again in
an outer select:

select * from
( select distinct on (b,n) b,n,stamp from  table where ... order by b,n,stamp ) ss
order by stamp;
        regards, tom lane


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

Предыдущее
От: Nicolas Beuzeboc
Дата:
Сообщение: Re: Special grouping on sorted data.
Следующее
От: "Oliveiros Cristina"
Дата:
Сообщение: Re: exclusion query