Re: Iterative Calculations

From: Hans Mayr <>
Date: Fri, 14 Aug 2009 05:30:05 -0700 (PDT)
Message-ID: <>

On 14 Aug., 14:21, "Álvaro G. Vicario"
<> wrote:
> Hans Mayr escribió:
> > I have a table that contains the fields PERIOD, STOCK, NEW_UNITS,
> > CHURN_RATE. STOCK is only available for a given start period. I want
> > to update the expected stock of the next periods. Is there a way that
> > in pure SQL (without PL SQL and a cursor) I can calculate
> > STOCK of PERIOD (N) = STOCK of PERIOD (N-1) * (1-CHURN_RATE) +
> Perhaps you can use the LAG function:


no, I don't think so. Because the lag goes to a fiel in the preceeding line of a certain object. But I need to refer to a calculation, actually the calculation has to refer to itself. Maybe I was not clear but I do not only want to calculate the Stock for one following period but for many. So the result n has to become the source of result n+1 etc.

If I did not express myself clearly enough, please tell me.


Hans Received on Fri Aug 14 2009 - 07:30:05 CDT

Original text of this message