[데이터 베이스] 10-3. 파티션 별 순위 구하기

귤's avatar
Feb 28, 2025
[데이터 베이스] 10-3. 파티션 별 순위 구하기

파티션

partition by
-- 4. 파티션 -- 순위를 그룹별로 하고 싶다. select deptno, ename, sal, rank() over (partition by deptno order by sal desc) '순위' from emp order by deptno;
notion image

파티션 연습

-- 5. 파티션 연습 (jumin에 있는 75, 76 등 나이별 키 (height) 순위를 구하시오.) select * from student; select jumin, name, height from student order by jumin; select name, jumin, height, rank () over (partition by jumin order by height desc) '순위' from ( select name, substr(jumin, 1, 2) 'jumin', height from student ) st;
notion image

(1) 전체 검색 먼저!!

select * from student;
notion image

(2) 필요한 데이터만 보이게 출력!

select jumin, name, height from student order by jumin;
notion image

(3) 나이, 키 별로 순위 구하기

select name, jumin, height, rank () over (partition by jumin order by height desc) '순위' from ( select name, substr(jumin, 1, 2) 'jumin', height from student ) st;
notion image
 
Share article

gyul