Please look at the query. My requirement is to add the distributed sales untill opportunity rating is found not 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.
can give you column.
SKU, STORE_NUM,YEAR_WEEK_KEY, DISTRIBUTED_SALES_PLAN, PSW_FLAG, END_OF_WEEK_ONHAND,OPPORTUNITY_RATING.
OPPORTUNITY RATING WILL Be updated only where it is not null value.
1. sum(decode(psw_fald,0,0 DISTRIBUTED_SALES_PLaN)) untill it finds OPPERTUNITY_rating NOT NULL. - this is the total it calculates
2. when it finds the oppertunity_rating it will take the EOWH value for that particuler row( OPPERTUNITY_RATING NOT NULL) and divides it by current total and reset the toatal and same thing untill it finds next not null OPPETUNITy for that
perticular sku, store_num. as showen in data table above.
This the logic it using for please
Please help me.
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.
can give you column.
SKU, STORE_NUM,YEAR_WEEK_KEY, DISTRIBUTED_SALES_PLAN, PSW_FLAG, END_OF_WEEK_ONHAND,OPPORTUNITY_RATING.
OPPORTUNITY RATING WILL Be updated only where it is not null value.
1. sum(decode(psw_fald,0,0 DISTRIBUTED_SALES_PLaN)) untill it finds OPPERTUNITY_rating NOT NULL. - this is the total it calculates
2. when it finds the oppertunity_rating it will take the EOWH value for that particuler row( OPPERTUNITY_RATING NOT NULL) and divides it by current total and reset the toatal and same thing untill it finds next not null OPPETUNITy for that
perticular sku, store_num. as showen in data table above.
This the logic it using for please
Please help me.
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_weekWHERE sku = 11769802
AND store_num = 96ORDER BY year_week_key DESC;
Code:
END_O_W_H DISTRIBUTEDPL_SAL TOTOL OPPORTUNITY_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 [b]0.8034 <-------94/117[/b]
2 12 [b]129<----------------should be 22(10+12)[/b]
2 14 14 [b]0.0909<-------- 2/22[/b]