X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A4FD45287E for ; Tue, 31 May 2005 13:37:02 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 43223-09 for ; Tue, 31 May 2005 16:36:56 +0000 (GMT) Received: from iracema.dnscenter.com.br (iracema.dnscenter.com.br [67.15.81.98]) by svr1.postgresql.org (Postfix) with ESMTP id D973252867 for ; Tue, 31 May 2005 13:36:52 -0300 (ADT) Received: from cpanel by iracema.dnscenter.com.br with local (Exim 4.51) id 1Dd9jV-00026c-7z for pgsql-sql@postgresql.org; Tue, 31 May 2005 13:36:49 -0300 Received: from 201.0.112.18 ([201.0.112.18]) by www.presserv.org (Horde) with HTTP for ; Tue, 31 May 2005 13:36:48 -0300 Message-ID: <20050531133648.cypdc5lnjtc0wsws@www.presserv.org> Date: Tue, 31 May 2005 13:36:48 -0300 From: lucas@presserv.org To: pgsql-sql@postgresql.org Subject: Sum() rows MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 7bit User-Agent: Internet Messaging Program (IMP) H3 (4.0) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - iracema.dnscenter.com.br X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [32001 502] / [47 12] X-AntiAbuse: Sender Address Domain - presserv.org X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.23 tagged_above=0 required=5 tests=AWL, NO_REAL_NAME X-Spam-Level: X-Archive-Number: 200505/242 X-Sequence-Number: 21555 Hi. How can I sum a row and show the sum for each row??? For example, in a finances table that have the total movimentation(debit/credit) in the bank. i.e: CREATE TABLE TB1 (id integer primary key, value numeric); insert into tb1 values (1,20); insert into tb1 values (2,2); insert into tb1 values (3,3); insert into tb1 values (4,17); insert into tb1 values (5,-0.5); insert into tb1 values (6,3); I want a query that returns: -id- | --- value --- | --- subtot --- 1 | 20.00 | 20.00 2 | 2.00 | 22.00 3 | 3.00 | 25.00 4 | 17.00 | 42.00 5 | -0.50 | 41.50 6 | 3.00 | 44.50 The subtot colum will be the "prev. subtot colum"+"value colum". :-/ I dont know how to make the "subtot" colum, I tried to use the sum() function but it not works correctly. Any idea??? Thanks.