res.rate = case when t2.budget_workload=0 or t2.budget_workload is null then if(t2.children_cnt=0 or t2.children_cnt is null,t2.total_rate,t2.total_rate/t2.children_cnt) else t2.budget_workload_rate / t2.budget_workload end,
res.rate = case when (t2.budget_workload=0 or t2.budget_workload is null) and (t2.act_workload is null or t2.act_workload =0 ) and t2.rworkload is null then if(t2.children_cnt=0 or t2.children_cnt is null,t2.total_rate,t2.total_rate/t2.children_cnt) else ifnull(t2.act_workload,0) / ifnull(t2.act_workload,0)+ifnull(t2.rworkload) end,
sum( ifnull( t.budget_workload, 0 )) as budget_workload,
@ -297,7 +300,7 @@
SET
res.act_cost = t2.act_cost,
res.act_workload = t2.act_workload,
res.rate = case when t2.budget_workload=0 or t2.budget_workload is null then if(t2.children_cnt=0 or t2.children_cnt is null,t2.total_rate,t2.total_rate/t2.children_cnt) else t2.budget_workload_rate / t2.budget_workload end,
res.rate = case when (t2.budget_workload=0 or t2.budget_workload is null) and (t2.act_workload is null or t2.act_workload =0 ) and t2.rworkload is null then if(t2.children_cnt=0 or t2.children_cnt is null,t2.total_rate,t2.total_rate/t2.children_cnt) else ifnull(t2.act_workload,0) / ifnull(t2.act_workload,0)+ifnull(t2.rworkload) end,
set res.act_workload=w.workload,res.rate=if(res.rworkload is null and ifnull(w.workload,0)>0 and res.budget_workload>0,ifnull(res.act_workload,0)*100 / (res.budget_workload),ifnull(w.workload,0)*100/(ifnull(w.workload,0)+res.rworkload))