Re: Incremental sum ?
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: "Ross J. Reedstrom" <reedstrm@rice.edu>
Cc: Alex Pilosov <alex@pilosoft.com>, Domingo Alvarez Duarte <domingo@dad-it.com>, pgsql-sql@postgresql.org
Date: 2001-06-22T16:58:46Z
Lists: pgsql-sql
"Ross J. Reedstrom" <reedstrm@rice.edu> writes: > And here's the working example: not the need to GROUP BY, and <= > to get the current payment. > select cust_id,invoice_id,val,paid, (select (sum(val) - sum(paid)) > from invoices_not_paid where cust_id= i.cust_id and invoice_id <= > i.invoice_id group by cust_id) as balance from invoices_not_paid i; Actually I think you could leave off the inner GROUP BY --- won't there always be exactly one group, since only one value of inner cust_id is selected? regards, tom lane