Re: Difficulties with LAG-function when calculating overtime - Mailing list pgsql-sql

From David G. Johnston
Subject Re: Difficulties with LAG-function when calculating overtime
Date
Msg-id CAKFQuwZjrGG5gtakGN7QMCgCZYYVcCUwXAWmvqdxvi_DbuK8Vw@mail.gmail.com
Whole thread Raw
In response to Difficulties with LAG-function when calculating overtime  (Andreas Joseph Krogh <andreas@visena.com>)
Responses Sv: Re: Difficulties with LAG-function when calculating overtime
List pgsql-sql
On Mon, Nov 19, 2018 at 6:24 AM Andreas Joseph Krogh <andreas@visena.com> wrote:
Anyone has a clever way to solve this kinds of issues and craft a query which produces the desired result as in the table above?

Thinking in terms of theory - you need to calculate the first row and then calculate the next row using data from the first row.  Then calculate the third row using data from the second row (you might need to carry-forward some value from the first row so that the third row can see them...).  That sounds like the algorithm for iteration which is implemented in SQL via "WITH RECURSIVE".

David J.

pgsql-sql by date:

Previous
From: Andreas Joseph Krogh
Date:
Subject: Difficulties with LAG-function when calculating overtime
Next
From: Andreas Joseph Krogh
Date:
Subject: Sv: Re: Difficulties with LAG-function when calculating overtime