with t(ACHIEVE,BONUS) as(
select 5, 0 from dual union all
select 10, 5 from dual union all
select 20, 6 from dual union all
select 30, 7 from dual union all
select 40, 8 from dual union all
select 140, 100 from dual)
select bonus
from (
select v,achieve,bonus
from t
model return updated rows
dimension by (rownum n)
measures (cast(0 as number) v,achieve,bonus)
ignore nav
rules (
v[any] = achieve[cv() - 1]
))
where least((100 / 50 ) * 100 ,140) between v+1 and achieve
;
WITH TT(ACHIEVE, BONUS) AS ( SELECT 5, 0 FROM DUAL UNION ALL SELECT 10, 5 FROM DUAL UNION ALL SELECT 20, 6 FROM DUAL UNION ALL SELECT 30, 7 FROM DUAL UNION ALL SELECT 40, 8 FROM DUAL UNION ALL SELECT 140, 100 FROM DUAL ) SELECT SS.ACHIEVE , CASE WHEN SS.ACHIEVE >= (SELECT MAX(ACHIEVE) FROM TT) THEN (SELECT MAX(BONUS) FROM TT) ELSE TT.BONUS END AS BONUS FROM TT , (SELECT (100 / 50 ) * 100 AS ACHIEVE FROM DUAL) SS WHERE TT.ACHIEVE(+) = SS.ACHIEVE ;
WITH code_t AS ( SELECT 5 achieve, 0 bonus FROM dual UNION ALL SELECT 10, 5 FROM dual UNION ALL SELECT 20, 6 FROM dual UNION ALL SELECT 30, 7 FROM dual UNION ALL SELECT 40, 8 FROM dual UNION ALL SELECT 140, 100 FROM dual ) , data_t AS ( SELECT (100 / 50 ) * 100 v FROM dual ) SELECT d.v , MAX(achieve) achieve , MAX(bonus) bonus FROM data_t d , code_t c WHERE d.v >= c.achieve ;