[결과] | |||
NAME | SCORE | RANKS | EVAL |
KIM2 | 100 | 1 | A |
KIM1 | 90 | 2 | B |
KIM3 | 80 | 3 | B |
KIM4 | 70 | 4 | C |
KIM5 | 50 | 5 | C |
WITH A AS ( SELECT 'KIM1' AS NAME , 90 AS SCORE FROM DUAL UNION ALL SELECT 'KIM2' AS NAME , 100 AS SCORE FROM DUAL UNION ALL SELECT 'KIM3' AS NAME , 80 AS SCORE FROM DUAL UNION ALL SELECT 'KIM4' AS NAME , 70 AS SCORE FROM DUAL UNION ALL SELECT 'KIM5' AS NAME , 50 AS SCORE FROM DUAL UNION ALL SELECT 'KIM6' AS NAME , 40 AS SCORE FROM DUAL ) SELECT NAME , SCORE , RANK() OVER (ORDER BY SCORE DESC) AS RANKS , CASE WHEN COUNT(*) OVER (ORDER BY SCORE DESC)/COUNT(*) OVER(PARTITION BY 1) <= 0.2 THEN 'A' WHEN COUNT(*) OVER (ORDER BY SCORE DESC)/COUNT(*) OVER(PARTITION BY 1) <= 0.6 THEN 'B' ELSE 'C' END AS EVAL FROM A;
with a as ( select 'KIM1' as NAME , 90 as SCORE from dual union all select 'KIM2' as NAME , 100 as SCORE from dual union all select 'KIM3' as NAME , 80 as SCORE from dual union all select 'KIM4' as NAME , 70 as SCORE from dual union all select 'KIM5' as NAME , 50 as SCORE from dual union all select 'KIM6' as NAME , 40 as SCORE from dual ) SELECT a.* , CASE WHEN RATIO <= 0.2 THEN 'A' WHEN RATIO <= 0.6 THEN 'B' ELSE 'C' END AS EVAL FROM (select NAME, SCORE, RANK() OVER (ORDER BY SCORE DESC) AS RANKS , RANK() OVER (ORDER BY SCORE DESC) / MAX(ROWNUM) OVER() AS RATIO FROM A) a