Re: Difficulties with LAG-function when calculating overtime

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Andreas Joseph Krogh <andreas(at)visena(dot)com>
Cc: pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re: Difficulties with LAG-function when calculating overtime
Date: 2018-11-19 16:08:57
Message-ID: CAKFQuwZjrGG5gtakGN7QMCgCZYYVcCUwXAWmvqdxvi_DbuK8Vw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Mon, Nov 19, 2018 at 6:24 AM Andreas Joseph Krogh <andreas(at)visena(dot)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.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Andreas Joseph Krogh 2018-11-19 16:20:23 Sv: Re: Difficulties with LAG-function when calculating overtime
Previous Message Andreas Joseph Krogh 2018-11-19 13:27:01 Difficulties with LAG-function when calculating overtime