Re: Sorted group by

Поиск
Список
Период
Сортировка
От Thomas Kellerer
Тема Re: Sorted group by
Дата
Msg-id i3rsrr$23e$1@dough.gmane.org
обсуждение исходный текст
Ответ на Sorted group by  (Matthew Wakeling <matthew@flymine.org>)
Ответы Re: Sorted group by
Список pgsql-performance
Matthew Wakeling wrote on 10.08.2010 17:40:
> Currently, I do this in my application by ordering by the number and
> only using the last value. I imagine that this is something that can be
> done in the new Postgres 9, with a sorted group by - something like this:
>
> SELECT group, LAST(value, ORDER BY number) FROM table GROUP BY group
>
> Is this something that is already built in, or would I have to write my
> own LAST aggregate function?

No. It's built in (8.4) and it's called Windowing functions:
http://www.postgresql.org/docs/8.4/static/tutorial-window.html
http://www.postgresql.org/docs/8.4/static/functions-window.html

SELECT group, last_value(value) over(ORDER BY number)
FROM table

You don't need the group by then (but you can apply e.g. an ORDER BY GROUP)

Thomas

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

Предыдущее
От: Matthew Wakeling
Дата:
Сообщение: Sorted group by
Следующее
От: Matthew Wakeling
Дата:
Сообщение: Re: Sorted group by