Re: Windowing ?

Andreas Kretschmer <[email protected]>
Newsgroups gmane.comp.db.postgresql.sql
Message-ID <[email protected]>

Am 11.12.2017 um 18:09 schrieb Olivier Leprêtre:
>
> Hi,
>
> I have a table describing sort of ordered road segments and their 
> associated weight. I would like to calculate weight deltas between two 
> consecutive segments. Problem is to substract previous from current 
> row and reuses result as input for the next row.
>

You can use the lag() - function.

select ..., lag(weight) over (partition by road order by segment) ...



Regards, Andreas

-- 
2ndQuadrant - The PostgreSQL Support Company.
www.2ndQuadrant.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.