Re: Incremental sum ?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Ross J(dot) Reedstrom" <reedstrm(at)rice(dot)edu>
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 16:58:46
Message-ID: 4526.993229126@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"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?

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Alex Pilosov 2001-06-22 17:00:02 Re: View performance question
Previous Message Peter Eisentraut 2001-06-22 16:56:34 Re: cache lookup failed ???? What is it ???!!!