μλμ° ν¨μλ?
- μλμ° ν¨μλ μ€λΌν΄ λΏλ§ μλλΌ SQL Server, PostgreSQL, MySQL(8.0 μ΄μ) λ± λ€μν SQL λ°μ΄ν°λ² μ΄μ€ μμ€ν μμ μ¬μ©ν μ μμ
- μ΄ ν¨μλ€μ λ°μ΄ν°λ₯Ό κ·Έλ£Ήννκ³ κ° κ·Έλ£Ή λ΄μμ 볡μ‘ν κ³μ°μ μνν λ μ¬μ©
μλμ° ν¨μ
- ROW_NUMBER(): κ° νν°μ λ΄μμμ ν μμλ₯Ό λ°νν¨
- RANK(): νΉμ μμμ λ°λΌ κ° νμ μμλ₯Ό 맀κΉ. κ°μ κ°μ΄λ©΄ κ°μ μμλ₯Ό λΆμ¬νλ©°, μμμ κ³΅λ°±μ΄ μμ μ μμ
- DENSE_RANK(): RANK()μ μ μ¬νμ§λ§, 곡백 μλ μ°μμ μΈ μμλ₯Ό λΆμ¬ν¨
- SUM(): νν°μ λ΄μμμ ν©κ³λ₯Ό κ³μ°
- AVG(): νν°μ λ΄μμμ νκ· κ°μ κ³μ°
- MIN() λ° MAX(): νν°μ λ΄μμμ μ΅μκ°κ³Ό μ΅λκ°μ κ³μ°
- LEAD() λ° LAG(): λ€μ νμ΄λ μ΄μ νμ κ°μ λ°νν¨
μ¬μ© μμ νν
SELECT
ROW_NUMBER() OVER (PARTITION BY column1 ORDER BY column2) AS row_num,
RANK() OVER (PARTITION BY column1 ORDER BY column2) AS rank,
DENSE_RANK() OVER (PARTITION BY column1 ORDER BY column2) AS dense_rank,
SUM(column3) OVER (PARTITION BY column1) AS sum_column3,
AVG(column3) OVER (PARTITION BY column1) AS avg_column3
FROM
table_name;
- μ΄ μΏΌλ¦¬λ column1μ κΈ°μ€μΌλ‘ λ°μ΄ν°λ₯Ό νν°μ νκ³
- column2μ μμμ λ°λΌ κ° νμ λν ROW_NUMBER, RANK, DENSE_RANKλ₯Ό κ³μ°νλ©°
- column3μ ν©κ³μ νκ· μ κ° νν°μ λ³λ‘ κ³μ°ν¨
'π₯οΈ λ°μ΄ν°λ² μ΄μ€ > SQL' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[Oracle] JoinμΌλ‘ λ°μ΄ν° μ°κ²°, Set μ°μ°μ (1) | 2024.01.05 |
---|---|
[Oracle] SubGroupμΌλ‘ λ°μ΄ν° λΆλ₯ (0) | 2024.01.05 |
[Oracle] ν μ΄λΈ μμ± λ° λ°μ΄ν° μ‘°μ (0) | 2024.01.05 |
[Oracle] ν μ΄λΈ μμ± λ° λ°μ΄ν° μ‘°μ (2) | 2023.11.11 |
[Oracle] SQLμ΄λ (1) | 2023.11.11 |