From: | lucas(at)presserv(dot)org |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Sum() rows |
Date: | 2005-05-31 16:36:48 |
Message-ID: | 20050531133648.cypdc5lnjtc0wsws@www.presserv.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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.
From | Date | Subject | |
---|---|---|---|
Next Message | Bruno Wolff III | 2005-05-31 17:17:08 | Re: Sum() rows |
Previous Message | Tom Lane | 2005-05-31 16:00:13 | Re: (Mis)using the PostgreSQL planner to get estimated row counts |