9. 순위 지정하기

김해준's avatar
Dec 29, 2025
9. 순위 지정하기

랭킹구하기 기본

-- 랭킹 구하기 select deptno, ename, sal, row_number() over(order by sal desc) from emp;
notion image

동일 랭킹 처리(1,2,2,4,5,…)

-- 동일 랭킹의 처리(1,2,2,4,5,...) select deptno, ename, sal, rank() over(order by sal desc) from emp;
notion image

동일 랭킹 처리(1,2,2,3,4,…)

-- 동일 랭킹의 처리(1,2,2,3,4,...) select deptno, ename, sal, dense_rank() over(order by sal desc) from emp;
notion image

파티셔닝(구간을 지정하여 랭킹 처리)

-- 파티셔닝(구간을 지정하여 순위 설정) select ename, job, sal, dense_rank() over(partition by job order by sal desc) from emp;
notion image
 

파티셔닝 노가다

-- 3. 파티셔닝 순위 노가다 -- 합집합 (union, union all) -- union -> 합칠 때 동일한 내용이 있으면 하나로 합쳐버림(연산 많음) -- union all -> 동일한 내용이 있어도 그대로 합침(단순 합침) -- 합집합 시 컬럼의 개수가 같아야 함 select deptno, ename, sal, job, empno, dense_rank() over (order by sal desc) from emp where job = 'ANALYST' union all select deptno, ename, sal, job, null, dense_rank() over (order by sal desc) from emp where job = 'CLERK';
notion image
Share article