X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.225.181]) by svr1.postgresql.org (Postfix) with ESMTP id E354DCB571 for ; Tue, 15 Jul 2003 12:16:48 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr5.postgresql.org [64.117.225.181]) (amavisd-new, port 10024) with ESMTP id 95501-07 for ; Tue, 15 Jul 2003 12:17:03 +0000 (GMT) Received: from mail1.dr.myx.net (mail1.dr.myx.net [217.10.193.161]) by svr1.postgresql.org (Postfix) with ESMTP id 8658FCC24D for ; Tue, 15 Jul 2003 09:16:37 -0300 (ADT) Received: from workstation24 (unknown [81.12.137.146]) by mail1.dr.myx.net (mydomain.myx.net) with ESMTP id 44F8830075B for ; Tue, 15 Jul 2003 15:16:55 +0300 (EEST) Message-ID: <001501c34aca$e70ca280$0600a8c0@fix.ro> From: "Viorel Dragomir" To: References: <20030715140921.7c5a6a6c.erik@thiele-hydraulik.de> Subject: Re: summing tables Date: Tue, 15 Jul 2003 15:16:21 +0300 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/162 X-Sequence-Number: 14276 update table_name set c = a + b + (select c from table_name as x where x.seq = seq-1) where c is null; additional checks are required if you want to update c when c is not null if all the c are null then this query will do nothing god help u :) ----- Original Message ----- From: "Erik Thiele" To: Sent: Tuesday, July 15, 2003 3:09 PM Subject: [SQL] summing tables > 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 > > > -- > Erik Thiele > > ---------------------------(end of broadcast)--------------------------- > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org