2

必要な結果が得られない CONNECT BY クエリがあります。

最後のサブクエリとクエリは、パーセンテージの文字列を掛け合わせた積を生成することになっています。

それは、年ごとの保持率 (PCT) の表から始まります。クエリが進行するにつれて、最初の年からの PCT を取得し、次の年の PCT を掛けて、必要な深さに達するまで繰り返します。この効果は、YR (年) と yset が開始行と列を表すクロス集計で対角線を乗算するようなものであると想定されています。

クエリが進行するにつれて完全な文字列を取得する代わりに、最後の 2 つのパーセンテージの結果のみを取得しています。

単純な間違いかもしれませんが、余分な目があると、より迅速に見つけることができます。

コード:

     with recurreten as
(
select  YR, YSet, 
      rtnpct rtn_year, 
      level lvl, ' - ' s1,   
      rtnpct * nvl( prior rtnpct, 1)  rtnpct 
      --- Below here only for checking the paths
      , sys_connect_by_path( nvl(rtnpct, 1) , '/')  prodpath 
from Z_RETENTIONPCT
    connect by yr = prior yr+1 and yset  = prior yset+1
    start with YR = 1998  -- :StartYr
               and
               yset = 20  -- :StartYSet
)

-- final results
select yr, yset, 
      round(rtn_year * 100, 2 ) rtn_year,   
      lvl, -- years the Cumulative Continuation Rate is extended
      s1,  
      round(rtnpct, 2) CCR  
      --- Below here only for checking results
      , rtnpct CCRFull -- Extra digits, for math check
      , prodpath  -- Only used by us, to check the #'s feeding the CCR
from recurreten
where  lvl <= 10 -- :Depth     
order by yr, yset, lvl
;

http://sqlfiddle.com/#!4/ce945/1/0で SQLFiddle に例を設定しました
。この例では、WITH を使用してダミー データを設定しています。

結果の例: (望ましい結果)

Year    Col     Reten_yr    Full prod    Full Prod Path
1998    20      0.84766     0.847660000  = 0.84766
1999    21      0.77941     0.660674681  = 0.84766 * 0.77941
2000    22      0.78659     0.519680097  = 0.84766 * 0.77941 * 0.78659
2001    23      0.76879     0.399524862  = 0.84766 * 0.77941 * 0.78659 * 0.76879

(現在/間違った結果)

Year    Col     Reten_yr    wrong prod   Partial Path
1998    20      0.84766     0.847660000  = 0.84766
1999    21      0.77941     0.660674681  = 0.84766 * 0.77941
2000    22      0.78659     0.613076112  =           0.77941 * 0.78659
2001    23      0.76879     0.604722526  =                     0.78659 * 0.76879

完全な (乗算) 積を取得できないのはなぜですか? これを修正するにはどうすればよいですか? 誰...?誰?ビューラー?

更新: Eat A Peach は、真に累積的な結果を得るために必要な修正を提供しました。通常のデータの範囲を隠したサンプル データを手動で調整したため、その例を更新する必要がありました。行は 50 年以上連続しており、毎年最大 70 の YCS があります。更新されたクエリは連続した累積積を実行し、私の要件は「斜めに連続した累積積」です。ログ追加ソリューションを保持し、CONNECT BY を追加し直しました。

http://sqlfiddle.com/#!4/1c326/2

開始点と深さのデフォルト値をいくつか示します。

再度、感謝します!

4

1 に答える 1