Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eORgY-00047j-DW for pgsql-sql@arkaria.postgresql.org; Mon, 11 Dec 2017 17:16:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eORgX-0007jv-OC for pgsql-sql@arkaria.postgresql.org; Mon, 11 Dec 2017 17:16:09 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eORgX-0007jm-FD for pgsql-sql@lists.postgresql.org; Mon, 11 Dec 2017 17:16:09 +0000 Received: from mail.i-mark.de ([188.138.104.222]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eORgU-0001Cf-BT for pgsql-sql@lists.postgresql.org; Mon, 11 Dec 2017 17:16:08 +0000 Received: from [192.168.222.106] (p54B09956.dip0.t-ipconnect.de [84.176.153.86]) by mail.i-mark.de (Postfix) with ESMTPSA id EE7B91582941 for ; Mon, 11 Dec 2017 18:15:52 +0100 (CET) Subject: Re: Windowing ? To: pgsql-sql@lists.postgresql.org References: <5a2ebbc9.8a1f1c0a.ea0ea.7b4a@mx.google.com> From: Andreas Kretschmer Message-ID: Date: Mon, 11 Dec 2017 18:15:56 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <5a2ebbc9.8a1f1c0a.ea0ea.7b4a@mx.google.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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