Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gOmFJ-0006bf-Lf for pgsql-sql@arkaria.postgresql.org; Mon, 19 Nov 2018 16:17:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gOmFI-0006Cg-5H for pgsql-sql@arkaria.postgresql.org; Mon, 19 Nov 2018 16:17:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gOmFH-0006CW-N4 for pgsql-sql@lists.postgresql.org; Mon, 19 Nov 2018 16:17:55 +0000 Received: from post.visena.com ([46.226.10.50]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gOmFF-0000VR-3x for pgsql-sql@lists.postgresql.org; Mon, 19 Nov 2018 16:17:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=visena.com; s=20141101.wh; h=Content-Type:MIME-Version:Subject:In-Reply-To:Message-ID:Cc:To:From:Date; bh=xKlj3HeeEa6FhUlHn6cNJHFNG5jnIrV7Yp7G83loHdY=; b=OOFNEvwqcPi6XePGBjcTKvXPtnZ+zbbrgNuuo9up5mlIf9n9sPkcJA2mZ/Bfcww0srC4QyQw5z4j4ZUJyqGxK7ecHa0wZm6aEvtGCvul3luqpyjhhEvi7JHe64Do4sUUw4uv0vPyhMY7gbzgaten+KonD9q8Cg6PpPgp9hFyNXY=; Received: from [10.0.1.10] (helo=tc7-visena.wh.internal.visena.com) by post.visena.com with esmtp (Exim 4.82) (envelope-from ) id 1gOmFA-0004KL-TI; Mon, 19 Nov 2018 17:17:50 +0100 Received: from localhost ([127.0.0.1] helo=tc7-visena.wh.internal.visena.com) by tc7-visena.wh.internal.visena.com with esmtp (Exim 4.86_2) (envelope-from ) id 1gOmHf-0000v6-AT; Mon, 19 Nov 2018 17:20:23 +0100 Date: Mon, 19 Nov 2018 17:20:23 +0100 (CET) From: Andreas Joseph Krogh To: "David G. Johnston" Cc: pgsql-sql Message-ID: In-Reply-To: Subject: Sv: Re: Difficulties with LAG-function when calculating overtime MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_330_1856874021.1542644423238" X-Mailer: Visena Mail 2.1.175 X-Spam-Score: -1.0 X-Spam-Report: SpamAssasin (score=-1.0, required 5.0 ALL_TRUSTED=-1,HTML_MESSAGE=0.001) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_330_1856874021.1542644423238 Content-Type: multipart/related; boundary="----=_Part_331_1030850948.1542644423238" ------=_Part_331_1030850948.1542644423238 Content-Type: multipart/alternative; boundary="----=_Part_332_71528073.1542644423250" ------=_Part_332_71528073.1542644423250 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable P=C3=A5 mandag 19. november 2018 kl. 17:08:57, skrev David G. Johnston < david.g.johnston@gmail.com >: On Mon, Nov 19, 2018 at 6:24 AM Andreas Joseph Krogh > wrote: Anyone has a clever way to solve this kinds of issues and craft a query whi= ch=20 produces the desired result as in the table above? =C2=A0 Thinking in terms of theory - you need to calculate the first row and then= =20 calculate the next row using data from the first row.=C2=A0 Then calculate = the third=20 row using data from the second row (you might need to carry-forward some va= lue=20 from the first row so that the third row can see them...).=C2=A0 That sound= s like=20 the algorithm for iteration which is implemented in SQL via "WITH RECURSIVE= ". =C2=A0 David J. =C2=A0 Yea, I kind of figured RECURSIVE CTE was the way foreward... If anyone has got this working, give me a tip:-) =C2=A0 -- Andreas Joseph Krogh ------=_Part_332_71528073.1542644423250 Content-Type: text/html;charset=UTF-8 Content-Transfer-Encoding: quoted-printable
P=C3=A5 mandag 19. november 2018 kl. 17:08:57, skrev David G. Johnston= <david.g.johnston@gmail.c= om>:
On Mon, Nov 19, 2= 018 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 quer= y which produces the desired result as in the table above?
=C2=A0
Thinking in terms of theory - you need to calculate the first row and th= en calculate the next row using data from the first row.=C2=A0 Then calcula= te the third row using data from the second row (you might need to carry-fo= rward some value from the first row so that the third row can see them...).= =C2=A0 That sounds like the algorithm for iteration which is implemented in= SQL via "WITH RECURSIVE".
=C2=A0
David J.
=C2=A0
Yea, I kind of figured RECURSIVE CTE was the way foreward...
If anyone has got this working, give me a tip:-)
=C2=A0
">
--
Andrea= s Joseph Krogh
------=_Part_332_71528073.1542644423250-- ------=_Part_331_1030850948.1542644423238-- ------=_Part_330_1856874021.1542644423238--