[SQL/ORACLE] μˆœμœ„ ν•¨μˆ˜

DANIΒ·2023λ…„ 11μ›” 12일
0

ORACLE_SQL

λͺ©λ‘ 보기
10/10
post-thumbnail

πŸ” RANK ν•¨μˆ˜

RANK ν•¨μˆ˜λŠ” 쀑볡 값듀에 λŒ€ν•΄μ„œ 동일 μˆœμœ„λ‘œ ν‘œμ‹œν•˜κ³ , 쀑볡 μˆœμœ„ λ‹€μŒ 값에 λŒ€ν•΄μ„œλŠ” 쀑볡 개수만큼 떨어진 μˆœμœ„λ‘œ 좜λ ₯ν•˜λ„λ‘ ν•˜λŠ” ν•¨μˆ˜λ‹€.

πŸ”΄ μ˜ˆμ‹œ1

SELECT ENAME, JOB, DEPTNO, SAL, RANK() OVER(ORDER BY SAL DESC) RANKS
FROM EMP;

πŸ”΅ μ˜ˆμ‹œ1


πŸ” DENSE_RANK ν•¨μˆ˜

DENSE_RANK ν•¨μˆ˜λŠ” 쀑볡 값듀에 λŒ€ν•΄μ„œ 동일 μˆœμœ„λ‘œ ν‘œμ‹œν•˜κ³ , 쀑볡 μˆœμœ„ λ‹€μŒ 값에 λŒ€ν•΄μ„œλŠ” 쀑볡 κ°’ κ°œμˆ˜μ™€ 상관없이 순차적인 μˆœμœ„ 값을 좜λ ₯ν•˜λ„λ‘ ν•˜λŠ” ν•¨μˆ˜μ΄λ‹€.

πŸ”΄ μ˜ˆμ‹œ1

SELECT ENAME, JOB, DEPTNO, SAL, DENSE_RANK() OVER(ORDER BY SAL DESC) DENS_RANKS
FROM EMP;

πŸ”΅ μ˜ˆμ‹œ1


πŸ” ROW_NUMBER ν•¨μˆ˜

ROW_NUMBER ν•¨μˆ˜λŠ” 쀑볡 값듀에 λŒ€ν•΄μ„œλ„ 순차적인 μˆœμœ„λ₯Ό ν‘œμ‹œν•˜λ„λ‘ 좜λ ₯ν•˜λŠ” ν•¨μˆ˜ 이닀.

πŸ”΄ μ˜ˆμ‹œ1

SELECT ENAME, JOB, DEPTNO, SAL, ROW_NUMBER() OVER(ORDER BY SAL DESC) ROW_NUM
FROM EMP;

πŸ”΅ μ˜ˆμ‹œ1



πŸ” RANK ν•¨μˆ˜, DENSE_RANK ν•¨μˆ˜, ROW_NUMBER ν•¨μˆ˜ 비ꡐ

πŸ”΄ μ˜ˆμ‹œ1

SELECT ENAME, JOB, DEPTNO, SAL, RANK() OVER(ORDER BY SAL DESC) RANK, DENSE_RANK() OVER(ORDER BY SAL DESC) DENSE_RANK, ROW_NUMBER() OVER(ORDER BY SAL DESC) ROW_NUM
FROM EMP;

πŸ”΅ μ˜ˆμ‹œ1

RANKλŠ” 동일 μˆœμœ„, λ‹€λ‹€μŒ μˆœμ„œ
DENSE_RANKλŠ” 동일 μˆœμœ„, λ‹€μŒ μˆœμ„œ
ROW_NUMBERλŠ” λ‹€λ₯Έ μˆœμœ„



πŸ” NTILE ν•¨μˆ˜

NTILEν•¨μˆ˜λŠ” 뒀에 ν•¨κ»˜ μ μ–΄μ£ΌλŠ” 숫자 만큼으둜 등뢄을 ν•΄μ„œ μˆœμœ„λ₯Ό μ •ν•΄μ£ΌλŠ” ν•¨μˆ˜.

πŸ”΄ μ˜ˆμ‹œ1

SELECT ENAME, JOB, DEPTNO, SAL, NTILE(3) OVER (ORDER BY SAL DESC) NTILE
FROM EMP;

πŸ”΅ μ˜ˆμ‹œ1



πŸ” PARTITION BY ν•¨μˆ˜

νŠΉμ • 속성 λ³„λ‘œ ꡬ뢄을 ν•˜κ³ μž ν•  λ•Œ PARTITION BYμ ˆμ„ μ‚¬μš©

πŸ”΄ μ˜ˆμ‹œ1

SELECT ENAME, JOB, DEPTNO, SAL, RANK() OVER (PARTITION BY DEPTNO ORDER BY SAL DESC) RANK
FROM EMP;

πŸ”΅ μ˜ˆμ‹œ1

λΆ€μ„œλ²ˆν˜Έ λ³„λ‘œ κ΅¬λΆ„ν•œ μˆœμœ„


πŸ”΄ μ˜ˆμ‹œ2

SELECT ENAME, JOB, DEPTNO, SAL, DENSE_RANK() OVER (PARTITION BY JOB ORDER BY SAL DESC) DENSE_RANK
FROM EMP;

πŸ”΅ μ˜ˆμ‹œ2

μ§μ—…λ³„λ‘œ κ΅¬λΆ„ν•œ μˆœμœ„

0개의 λŒ“κΈ€