[오늘쿼리] RANK

놀아·2022년 4월 14일
0
SELECT ENAME, JOB, SAL, RANK() OVER (ORDER BY SAL DESC) 순위
	FROM EMP
    WHERE JOB IN ('ANALYST', 'MANAGER');

출력결과

ENAME | JOB | SAL | 순위
FORD | ANALYST | 3000 | 1
SCOTT | ANALYST | 3000 | 1
JONES | MANAGER | 2975 | 3
BLANK | MANAGER | 2850 | 4
CLARK | MANAGER | 2450 | 5

SELECT ENAME, JOB, SAL, 
	   RANK() OVER (PARTITION BY JOB ORDER BY SAL DESC) AS 순위
	FROM EMP

출력결과

ENAME | JOB | SAL | 순위
FORD | ANALYST | 3000 | 1
SCOTT | ANALYST | 3000 | 1
MILLER | CLERK | 1300 | 1
ADAMS | CLERK | 1100 | 2
JAMES | CLERK | 950 | 3
SMITH | CLERK | 800 | 4
JONES | MANAGER | 2975 | 1
BLANK | MANAGER | 2850 | 2
CLARK | MANAGER | 2450 | 3

profile
머리가 나쁘기 때문에 메모와 정리를 한뒤에 찾아보기

0개의 댓글