agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedFrom: Olivier Leprêtre <o.lepretre@gmail.com>
To: pgsql-sql@lists.postgresql.org
Subject: Windowing ?
Date: Mon, 11 Dec 2017 18:09:25 +0100
Message-ID: <5a2ebbc9.8a1f1c0a.ea0ea.7b4a@mx.google.com> (raw)
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. I tried some windowing tests but was
unsuccessful.
Input table :
road segment weight
1 1 80
1 2 5
1 3 3
2 1 75
2 2 8
2 3 12
2 4 3
The result should be a new delta column :
road segment weight delta
1 1 80 80 (80-0) first row
1 2 5 75 (80-5)
1 3 3 72 (75-3)
2 1 75 75 (75-0)
2 2 8 67 (75-8)
2 3 12 55 (67-12)
2 4 3 52 (55-3)
Thanks for any help,
By the way, thanks again to Andreas and Martin that unstucked my mind
yesterday as I was searching for complicated solutions when a very simple
one existed.
Have a good day (or good evening)
Olivier
---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel antivirus Avast.
https://www.avast.com/antivirus
view thread (3+ messages) latest in thread
Message-ID: <5a2ebbc9.8a1f1c0a.ea0ea.7b4a@mx.google.com>
Permalink: ../5a2ebbc9.8a1f1c0a.ea0ea.7b4a@mx.google.com/
Also on: postgresql.org/message-id/5a2ebbc9.8a1f1c0a.ea0ea.7b4a@mx.google.com
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: o.lepretre@gmail.com, pgsql-sql@lists.postgresql.org
Subject: Re: Windowing ?
In-Reply-To: <5a2ebbc9.8a1f1c0a.ea0ea.7b4a@mx.google.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox