By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
select sum(decode(t.is_wo_nds, 1, t.sum_wo_tax, t.sum_w_tax) * abs(t.excluded_from_delivery)) /
sum(decode(t.is_wo_nds, 1, decode(t.sum_wo_tax,0,1,t.sum_wo_tax), decode(t.sum_w_tax,0,1,t.sum_w_tax))) as coef
from (select 0 as is_wo_nds,
100 as sum_wo_tax,
100 as sum_w_tax,
1 as excluded_from_delivery
from dual
union all
select 0 as is_wo_nds,
100 as sum_wo_tax,
100 as sum_w_tax,
0 as excluded_from_delivery
from dual
union all
select 0 as is_wo_nds,
0 as sum_wo_tax,
0 as sum_w_tax,
1 as excluded_from_delivery
from dual) t
COEF |
---|
.4975124378109452736318407960199004975124 |
select sum(t.sum_w_tax * abs(t.excluded_from_delivery)) /
sum(t.sum_w_tax) as coef
from (select 0 as is_wo_nds,
100 as sum_wo_tax,
100 as sum_w_tax,
1 as excluded_from_delivery
from dual
union all
select 0 as is_wo_nds,
100 as sum_wo_tax,
100 as sum_w_tax,
0 as excluded_from_delivery
from dual
union all
select 0 as is_wo_nds,
0 as sum_wo_tax,
0 as sum_w_tax,
1 as excluded_from_delivery
from dual) t
COEF |
---|
.5 |