X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.192]) by svr1.postgresql.org (Postfix) with ESMTP id 5422DCC232 for ; Tue, 15 Jul 2003 12:17:27 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr4.postgresql.org [64.117.224.192]) (amavisd-new, port 10024) with ESMTP id 39720-05 for ; Tue, 15 Jul 2003 12:17:49 +0000 (GMT) Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.171]) by svr1.postgresql.org (Postfix) with ESMTP id 7F4E2CC234 for ; Tue, 15 Jul 2003 09:17:23 -0300 (ADT) Received: from [212.227.126.162] (helo=mrelayng.kundenserver.de) by moutng.kundenserver.de with esmtp (Exim 3.35 #1) id 19cOki-0008CJ-00 for pgsql-sql@postgresql.org; Tue, 15 Jul 2003 14:17:52 +0200 Received: from [217.230.205.127] (helo=ecologic.de) by mrelayng.kundenserver.de with asmtp (Exim 3.35 #1) id 19cOki-00086W-00; Tue, 15 Jul 2003 14:17:52 +0200 Message-ID: <3F13F0EE.8040700@ecologic.de> Date: Tue, 15 Jul 2003 14:17:50 +0200 From: Dani Oderbolz User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Erik Thiele , pgsql-sql@postgresql.org Subject: Re: summing tables References: <20030715140921.7c5a6a6c.erik@thiele-hydraulik.de> In-Reply-To: <20030715140921.7c5a6a6c.erik@thiele-hydraulik.de> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/163 X-Sequence-Number: 14277 Erik Thiele wrote: >hi, > >i have a table consisting of 4 integers. > >seq is for making the table ordered. (ORDER BY SEQ ASC) >a,b,c maybe null > > > seq | a | b | c >-----+----+----+--- > 0 | 1 | 2 | 3 > 1 | 1 | 2 | > 2 | 5 | 7 | > 3 | -2 | -4 | > > >i am needing a sql statement to do > >c=a+b+"the c of the row with seq one less than myself" > >this statement has to run over the whole table, in seq order. > > >how can this be acomplished??? > > >cu&thanks >erik > > > > Hi Erik, this should do the trick: (I have not yet considered the NULLS though...) UPDATE table t set c = a + b + (Select c from table tt where tt.seq = t.seq -1) Cheers, Dani