Incremental sum ?

From: domingo(at)dad-it(dot)com (Domingo Alvarez Duarte)
To: pgsql-sql(at)postgresql(dot)org
Subject: Incremental sum ?
Date: 2001-06-22 08:16:15
Message-ID: 70a76315.0106220016.2a3a6f0b@posting.google.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I have a problem that requires what I call a incremental sum, lets say
I have the folowing table (for simplicity):

table invoices_not_paid(cust_id int, invoice_id int, val numeric, paid
numeric);

with the folowing values:

cust_id invoice_id val paid
----------------------------------
1 23 10.50 3.40
1 34 5.70 0.0
1 67 23.89 4.50

I want show a list like this:

cust_id invoice_id val paid incremental_not_paid_sum
-----------------------------------------------------------------
1 23 10.50 3.40 (10.50 - 3.40) 7.10
1 34 5.70 0.0 (7.10 + 5.70 - 0.0) 12.80
1 67 23.89 4.50 (12.80 + 23.89 - 4.50) 31.19

The operations betwen () are showed only to explain how the
incremental_not_paid_sum is calculated, The operation requires a
reference to a previous column or a partial sum of columns till that
moment, someone has an idea how this can be done using sql ?

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Hiroshi Inoue 2001-06-22 08:17:45 RE: Difference between insert a tuple in a table by function and by datasheet
Previous Message Kristoff Bonne 2001-06-22 08:09:02 Re: pl/pgsql question (functions)