[오늘쿼리] RANK

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

좋은 웹페이지 즐겨찾기