Re: [SQL] Sum() rows

2005-06-01 Thread Bruno Wolff III
On Wed, Jun 01, 2005 at 08:49:00 -0300, [EMAIL PROTECTED] wrote: > Yes, > I tried it. In this table the query works fine, but in a big table > (with aprox. > 200.000 records) the query performace is very bad. > I tried it (in the example table): > SELECT *,(select sum(value) from tb1 as tb1_2 w

Re: [SQL] Sum() rows

2005-06-01 Thread lucas
Hi. The function works well... I will use your function and rewrite it to accept more than one select, becouse in this case you selected all records from tb1 table. In real case the table is bigger with many fields and I will work with some filters and some ordering (dynamically)... Thank you.

Re: [SQL] Sum() rows

2005-06-01 Thread lucas
Yes, I tried it. In this table the query works fine, but in a big table (with aprox. 200.000 records) the query performace is very bad. I tried it (in the example table): SELECT *,(select sum(value) from tb1 as tb1_2 where tb1_2.id<=tb1_1.id) as subtot from tb1 as tb1_1 order by id; In a small

Re: [SQL] Sum() rows

2005-05-31 Thread Mark Dilger
Mark Dilger wrote: [EMAIL PROTECTED] wrote: 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); ins

Re: [SQL] Sum() rows

2005-05-31 Thread Mark Dilger
[EMAIL PROTECTED] wrote: 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,

Re: [SQL] Sum() rows

2005-05-31 Thread PFC
The simplest would be to create a stored procedure like this : declare row as TB1%rowtype, and ret as (id integer, value numeric, subtot numeric) then : ret.subtot = 0 FOR row IN SELECT * FROM TB1 ORDER BY id DO ret.id = row.id ret.value = row.value ret.subtot = ret

Re: [SQL] Sum() rows

2005-05-31 Thread Andrew Hammond
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 [EMAIL PROTECTED] wrote: > 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 nu

Re: [SQL] Sum() rows

2005-05-31 Thread Alvaro Herrera
On Tue, May 31, 2005 at 01:36:48PM -0300, [EMAIL PROTECTED] wrote: > 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 think you can write an aggregate in, say PL/Python to do this. IIR

Re: [SQL] Sum() rows

2005-05-31 Thread Bruno Wolff III
On Tue, May 31, 2005 at 13:36:48 -0300, [EMAIL PROTECTED] wrote: > Hi. > How can I sum a row and show the sum for each row??? Since in your example the id field gives the ordering, you can use a subselect to add up the subtotal for rows with and id less than or equal to the value of id for the c

[SQL] Sum() rows

2005-05-31 Thread lucas
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