Re: Window function?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Window function?
Дата
Msg-id 490058.1654354231@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Window function?  (Robert Stanford <rstanford@gmail.com>)
Ответы Re: Window function?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-general
Robert Stanford <rstanford@gmail.com> writes:
> Can anyone suggest an elegant way to coalesce consecutive rows so only the
> first start time and last end time for each group of events (by input) is
> returned.

Window functions don't change the number of query result rows, so that
idea is a dead end.  The standard way to solve this is GROUP BY:

SELECT Input, MIN(Start) AS Start, MAX(End) AS End
FROM ...
GROUP BY Input
ORDER BY Input -- optional

If MIN/MAX don't quite express what you need to happen, then you
might need to write custom aggregates.  Point though is that
you want aggregation within GROUP BY groups, not windowing.

            regards, tom lane



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

Предыдущее
От: Robert Stanford
Дата:
Сообщение: Re: Window function?
Следующее
От: Jeff Janes
Дата:
Сообщение: Re: Why password authentication failed for user "postgres"?