SQL >> Base de Datos >  >> RDS >> Oracle

Productos acumulados en SQL sin CONNECT BY

SQL no tiene producto acumulado, pero puedes calcularlo con matemáticas: a*b = exp(ln(a)+ln(b)).

select YR,YSET,rtnpct,
 round(exp(sum(ln(rtnpct)) over (
   order by yr,yset rows between unbounded preceding and current row)),2) ccr
from Z_RETENTIONPCT;

La cláusula rows between unbounded preceding and current row hace la suma acumulativa.

Limitación: solo funciona con valores estrictamente positivos; un cero o negativo rompe el método.