From: | "Ross J(dot) Reedstrom" <reedstrm(at)rice(dot)edu> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Alex Pilosov <alex(at)pilosoft(dot)com>, Domingo Alvarez Duarte <domingo(at)dad-it(dot)com>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Incremental sum ? |
Date: | 2001-06-22 17:18:16 |
Message-ID: | 20010622121816.B14381@rice.edu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Fri, Jun 22, 2001 at 12:58:46PM -0400, Tom Lane wrote:
> "Ross J. Reedstrom" <reedstrm(at)rice(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Ross J. Reedstrom | 2001-06-22 17:28:02 | Re: What is a "tuple" |
Previous Message | Tom Lane | 2001-06-22 17:05:59 | Re: View performance question |