Re: Iterative Calculations

From: Hans Mayr <mayr1972_at_gmx.de>
Date: Fri, 14 Aug 2009 05:30:05 -0700 (PDT)
Message-ID: <f9642c78-452a-4b3a-8448-0bbc49611876_at_a26g2000yqn.googlegroups.com>



On 14 Aug., 14:21, "Álvaro G. Vicario"
<alvaro.NOSPAMTH..._at_demogracia.com.invalid> 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) +
> > NEW_UNITS
>
> Perhaps you can use the LAG function:

Hi,

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.

Best,

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

Original text of this message