From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ross J. Reedstrom <reedstrm@rice.edu>
Cc: Alex Pilosov <alex@pilosoft.com>
Cc: Domingo Alvarez Duarte <domingo@dad-it.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Incremental sum ?
Date: Fri, 22 Jun 2001 12:58:46 -0400
Message-ID: <4526.993229126@sss.pgh.pa.us> (raw)
In-Reply-To: <20010622112119.D13451@rice.edu>
References: <Pine.BSO.4.10.10106221127520.17823-100000@spider.pilosoft.com>
<20010622112119.D13451@rice.edu>
"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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, reedstrm@rice.edu, alex@pilosoft.com, domingo@dad-it.com
Subject: Re: Incremental sum ?
In-Reply-To: <4526.993229126@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox