From: Ross J. Reedstrom <reedstrm@rice.edu>
To: Tom Lane <tgl@sss.pgh.pa.us>
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:18:16 -0500
Message-ID: <20010622121816.B14381@rice.edu> (raw)
In-Reply-To: <4526.993229126@sss.pgh.pa.us>
References: <Pine.BSO.4.10.10106221127520.17823-100000@spider.pilosoft.com>
<20010622112119.D13451@rice.edu>
<4526.993229126@sss.pgh.pa.us>
On Fri, Jun 22, 2001 at 12:58:46PM -0400, Tom Lane wrote:
> "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?
Sure enough, it works fine. My internal rule: "can't use aggregates
without a group by" mis-fired.
Ross
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: reedstrm@rice.edu, tgl@sss.pgh.pa.us, alex@pilosoft.com, domingo@dad-it.com
Subject: Re: Incremental sum ?
In-Reply-To: <20010622121816.B14381@rice.edu>
* 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