Det du har brug for er kumulativ multiplikation. Men der er ingen sådan funktion, hverken som aggregeret eller analytisk funktion. Men matematik fortæller os, at multiplikation kan ændres til addition ved hjælp af logaritme .
a * b = exp(ln(a) + ln(b))
Brug dette i SUM som analytisk funktion. Det er ikke nødvendigt at bruge CONNECT BY-konstruktionen.
recurreten as
(
select YR, YSet,
rtnpct rtn_year,
round(exp(sum(ln(rtnpct)) over (order by yr, yset rows between unbounded preceding and current row)),2) ccr,
exp(sum(ln(rtnpct)) over (order by yr, yset rows between unbounded preceding and current row)) ccrfull
from Z_RETENTIONPCT
)
select * from recurreten
order by yr, yset
| YR | YSET | RTN_YEAR | CCR | CCRFULL |
|------|------|----------|------|----------------|
| 1998 | 20 | 0.84766 | 0.85 | 0.84766 |
| 1999 | 21 | 0.77941 | 0.66 | 0.6606746806 |
| 2000 | 22 | 0.78659 | 0.52 | 0.519680097013 |
| 2001 | 23 | 0.76879 | 0.4 | 0.399524861783 |
| 2002 | 24 | 0.80952 | 0.32 | 0.32342336611 |
| 2003 | 25 | 0.76316 | 0.25 | 0.246823776081 |
| 2004 | 26 | 0.82425 | 0.2 | 0.203444497435 |
| 2005 | 27 | 0.6992 | 0.14 | 0.142248392606 |
| 2006 | 28 | 0.77071 | 0.11 | 0.109632258666 |
| 2007 | 29 | 0.702 | 0.08 | 0.076961845583 |