Re: Windowing ?

From: Andreas Kretschmer <andreas(at)a-kretschmer(dot)de>
To: pgsql-sql(at)lists(dot)postgresql(dot)org
Subject: Re: Windowing ?
Date: 2017-12-11 17:15:56
Message-ID: f02993c7-c740-e99b-e0e2-010a36ded92d@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

  • Windowing ? at 2017-12-11 17:09:25 from Olivier Leprêtre

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Andreas Kretschmer 2017-12-11 18:46:50 Re: Windowing ?
Previous Message Olivier Leprêtre 2017-12-11 17:09:25 Windowing ?