Help with Analytical Function
Please look at the query. My requeirment in to add the distributed sales untill opportunity rating is found no null. As soon as it finds opportunity rating take that total and devide end_of_week_on_hand by the total. and reset that total and start adding again till another oppertunity rating is found. once found end_of_week_ on_hand/total.
Please look at the query and i am getting some result but I am not able to reset and devide by total and after I get those value I have to update opportunity_rating of the same table where it finds not null value of oppertunity rating.
Code:
SELECT /*+ INDEX (ss_sku_store_week ss_sku_str_wk_pk) */
end_of_week_on_hand
, DECODE(psw_flag,
0, 0, distributed_planned_sales ) distributedplannedsales
, SUM(DECODE(psw_flag, 0, 0, distributed_planned_sales ) )
OVER ( PARTITION BY opportunity_rating ORDER BY year_week_key DESC) as totol,
opportunity_rating
FROM ss_sku_store_week
WHERE sku = 11769802
AND store_num = 96
ORDER BY year_week_key DESC;
Code:
END_OF_W_O_HAND DISTRIBUTEDSALES TOTOL OPP._RATING
-7 7 7
-11 11 18
-5 8 26
3 6 32
9 13 45
22 9 54
31 7 61
38 6 67
44 6 73
50 5 78
55 6 84
61 5 89
66 5 94
71 6 100
77 8 108
85 9 117
94 10 10 0.8034 <---this value (94/117)
2 12 129 <-------------------this value should be (10+12)=22
2 14 14 [B]0.0909[/B]<-----this value(2/22)