Reset Running total when either column value changes using Oracle Analytics -


i wants add column view keeps running total of value column. column must reset running total when either cat or cat b changes in rows. output data must this:-

cat  cat b    value   running total =====  =====    =====   ============= 0        1       15  0        1       235  0        1       306      556 0        0         1        2       85        85 1        1       105      105  0        2       600 0        2       70       670 0        3       564 0        3       101      665 0        1       30        30 

first, need column specify ordering running sum. assume called id.

second, seem have logic not have values on rows. not clear logic is. proper "running sum" defined on rows.

then, can use lag() , sum() define groups , use "analytic" sum() running sum:

select t.cata, t.catb, t.value,        sum(value) on (partition grp order id) runningsum (select t.*,              sum(case when cata = prev_cata , catb = prev_catb 0                       else 1                   end) on (order id) grp       (select t.*, lag(cata) on (order id) prev_cata,                    lag(catb) on (order id) prev_catb             t            ) t      ) t; 

Comments