Re: SQL Help - Finding Next Lowest Value of Current Row Value
В списке pgsql-general по дате отправления:
| От | Thomas Kellerer |
|---|---|
| Тема | Re: SQL Help - Finding Next Lowest Value of Current Row Value |
| Дата | |
| Msg-id | j694rn$2kj$1@dough.gmane.org обсуждение исходный текст |
| Ответ на | SQL Help - Finding Next Lowest Value of Current Row Value (Jeff Adams <Jeff.Adams@noaa.gov>) |
| Список | pgsql-general |
Jeff Adams wrote on 01.10.2011 23:30:
> Greetings,
>
> I have a large table (~19 million records). Records contains a field
> identifying a vessel and a field containing an time (epoch). Using the
> current rows vessel and time values, I need to be able to find the next
> lowest time value for the vessel and use it to compute how much time has
> elapsed between the records. I have tried a scalar subquery in the SELECT,
> which works, but it runs quite slowly. Is there an alternative approach that
> might perform better for this type of query. Any information would be
> greatly appreciated. Thanks...
>
> Jeff
Something like:
SELECT vessel,
time_column,
time_column - lag(time_column) over (partition by vessel order by time_column) as diff
FROM your_table
No sure how good that performs though.
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера