with t as (select 1 no, 1 plus, 2 double from dual union all select 2, 1, 3 from dual union all select 3, 4, 2 from dual) select no , p plus , d double , r result from t model dimension by (no) measures(plus p, double d, 0 r) rules(r[1] = p[cv()] * d[cv()] , r[2] = (r[1] + p[cv()]) * d[cv()] , r[3] = (r[2] + p[cv()]) * d[cv()]) ;
기타 문법 추가해 봅니다.
with t as (select 1 no, 1 plus, 2 double from dual union all select 2, 1, 3 from dual union all select 3, 4, 2 from dual union all select 4, 4, 2 from dual ) select no , p plus , d double , r result from t model dimension by (no) measures(plus p, double d, 0 r) ignore nav rules( r[any] = (r[cv()-1] + p[cv()]) * d[cv()] ) ;
WITH t AS ( SELECT 1 no, 1 plus, 2 double FROM dual UNION ALL SELECT 2, 1, 3 FROM dual UNION ALL SELECT 3, 4, 2 FROM dual ) , tmp(no, plus, double, r) AS ( SELECT no, plus, double , plus * double r FROM t WHERE no = 1 UNION ALL SELECT b.no, b.plus, b.double , (a.r + b.plus) * b.double r FROM tmp a, t b WHERE a.no + 1 = b.no ) SELECT * FROM tmp ;
WITH T AS (SELECT 1 NO,1 PLUS, 2 DOUBLE FROM DUAL UNION ALL SELECT 2, 1, 3 FROM DUAL UNION ALL SELECT 3, 4, 2 FROM DUAL) SELECT NO_A,SUM(R_C) FROM ( SELECT NO_A,NO_B,EXP(SUM(LN(R_C))) AS R_C FROM ( SELECT NO_A,NO_B,NO_C, DECODE(P_C,MIN_C,MIN_C,1)*D_C AS R_C FROM ( SELECT A.NO AS NO_A,B.NO AS NO_B,C.NO AS NO_C, C.PLUS AS P_C,C.DOUBLE AS D_C, MIN(C.PLUS) OVER(PARTITION BY A.NO,B.NO) AS MIN_C FROM T A, T B, T C WHERE A.NO >= B.NO AND A.NO >= C.NO AND B.NO <= C.NO ORDER BY NO_A,NO_B,NO_C ) ) GROUP BY NO_A,NO_B ) GROUP BY NO_A ORDER BY NO_A
WITH t(no, plus, double) AS ( SELECT 1, 1, 2 FROM dual UNION ALL SELECT 2, 1, 3 FROM dual UNION ALL SELECT 3, 4, 2 FROM dual ) SELECT rno no , MAX(DECODE(lv, 1, plus )) plus , MAX(DECODE(lv, 1, double)) double , SUM(r) r FROM (SELECT rno, lv , no, plus, double , ROUND( EXP(SUM(LN(double)) OVER(PARTITION BY rno ORDER BY lv)) ) * plus r FROM (SELECT no, plus, double , LEVEL lv , CONNECT_BY_ROOT no rno FROM t CONNECT BY PRIOR no - 1 = no ) ) GROUP BY rno ;
WITH t(no, plus, double) AS ( SELECT 1, 1, 2 FROM dual UNION ALL SELECT 2, 1, 0 FROM dual UNION ALL SELECT 3, 4, 2 FROM dual ) SELECT rno no , MAX(DECODE(lv, 1, plus )) plus , MAX(DECODE(lv, 1, double)) double , SUM(r) r FROM (SELECT rno, lv , no, plus, double , ROUND( -- 아주 작은 수(0.000000001) 을 더해서 에러 회피 -- EXP(SUM(LN(double + 1E-9)) OVER(PARTITION BY rno ORDER BY lv)) ) * plus r FROM (SELECT no, plus, double , LEVEL lv , CONNECT_BY_ROOT no rno FROM t CONNECT BY PRIOR no - 1 = no ) ) GROUP BY rno ;
WITH T AS ( SELECT 1 AS NO, 1 AS PLUS, 2 AS DOUBLE FROM DUAL UNION ALL SELECT 2, 2, -1 FROM DUAL UNION ALL SELECT 3, 3, 2 FROM DUAL ) SELECT RNO NO , MAX(DECODE(LV, 1, PLUS )) PLUS , MAX(DECODE(LV, 1, DOUBLE)) DOUBLE , SUM(R) R FROM ( SELECT RNO, LV , NO, PLUS, DOUBLE,R*PLUS*MIN(DIGN) OVER(PARTITION BY RNO ORDER BY LV) AS R FROM ( SELECT RNO, LV , NO, PLUS, DOUBLE , ROUND( EXP(SUM(LN(ABS(double)+ (1E-9))) OVER(PARTITION BY RNO ORDER BY LV)) ) R, SIGN(DECODE(DOUBLE,0,1,DOUBLE)) AS DIGN FROM ( SELECT NO, PLUS, DOUBLE , LEVEL LV , CONNECT_BY_ROOT NO RNO FROM T CONNECT BY PRIOR NO - 1 = NO ) ORDER BY RNO,LV ) ) GROUP BY RNO
WITH t(no, plus, double) AS ( SELECT 1, 1, 2 FROM dual UNION ALL SELECT 2, 2, -1 FROM dual UNION ALL SELECT 3, 3, -2 FROM dual ) SELECT rno no , MAX(DECODE(lv, 1, plus )) plus , MAX(DECODE(lv, 1, double)) double , SUM(r * plus * dign) r FROM ( SELECT rno, lv , no, plus, double , ROUND( EXP(SUM(LN(ABS(double) + 1E-9)) OVER(PARTITION BY rno ORDER BY lv)) ) r , DECODE(MOD(LENGTH(p) - LENGTH(REPLACE(p, '-')), 2), 0, 1, -1) dign FROM ( SELECT no, plus, double , LEVEL lv , CONNECT_BY_ROOT no rno , SYS_CONNECT_BY_PATH(SIGN(double), ',') p FROM t CONNECT BY PRIOR no - 1 = no AND 0 NOT IN (PRIOR double, double) ) ) GROUP BY rno ;