RANK ν¨μλ νΉμ νλͺ© λ° νν°μ μ λν΄μ μμλ₯Ό κ³μ°νλ ν¨μλ‘ λμΌν μμλ λμΌν κ°μ΄ λΆμ¬λλ€.
κΈ°λ³Έ ꡬ쑰λ λ€μκ³Ό κ°λ€.
SELECT [컬λΌλͺ
],
RANK() OVER (ORDER BY [컬λΌλͺ
] ASC/DESC)
FROM [ν
μ΄λΈλͺ
]
WHERE [쑰건μ];
INSERT INTO mytable
(name, model_num, model_type, lowest_price)
VALUES('i3', '13700KF', 'μλλ μ΄ν¬', 287240);
SELECT model_num, lowest_price,
RANK() OVER (ORDER BY lowest_price ASC) AS price_rank
FROM mytable
WHERE lowest_price BETWEEN 200000 AND 500000;
DENSE_RANK ν¨μλ RANK ν¨μμ λ§μ°¬κ°μ§λ‘ νΉμ νλͺ© λ° νν°μ μ λν΄μ μμλ₯Ό κ³μ°νλ ν¨μμ΄λ RANK ν¨μμ λ€λ₯΄κ² λμΌν μμλ₯Ό νλμ 건μλ‘ κ³μ°νλ€.
κΈ°λ³Έ ꡬ쑰λ λ€μκ³Ό κ°λ€.
SELECT [컬λΌλͺ
],
DENSE_RANK() OVER (ORDER BY [컬λΌλͺ
] ASC/DESC)
FROM [ν
μ΄λΈλͺ
]
WHERE [쑰건μ];
SELECT model_num, lowest_price,
DENSE_RANK() OVER (ORDER BY lowest_price ASC) AS price_rank
FROM mytable
WHERE lowest_price BETWEEN 200000 AND 500000;
μ κ·Έλ¦Όμμ κ°μ΄ RANK ν¨μμ λ€λ₯΄κ² 325,760μμ λ°μ΄ν°κ° 4μμμ 3μλ‘ λ°λκ²μ μ μ μλ€. μ΄λ 2μμΈ 287,240μμ λ°μ΄ν°λ₯Ό λ κ°μ 건μκ° μλ νλμ 건μλ‘ κ³μ°νκΈ° λλ¬Έμ΄λ€.
ROW_NUMBER ν¨μλ νΉμ νλͺ©μ λν΄μ μμλ₯Ό κ³μ°ν ν λμΌν μμμ λν΄μ κ³ μ μ μμλ₯Ό λΆμ¬νλ€.
κΈ°λ³Έ ꡬ쑰λ λ€μκ³Ό κ°λ€.
SELECT [컬λΌλͺ
],
ROW_NUMBER() OVER (ORDER BY [컬λΌλͺ
] ASC/DESC)
FROM [ν
μ΄λΈλͺ
]
WHERE [쑰건μ];
SELECT model_num, lowest_price,
ROW_NUMBER() OVER (ORDER BY lowest_price ASC) AS price_rank
FROM mytable
WHERE lowest_price BETWEEN 200000 AND 500000;
SELECT model_num, lowest_price,
RANK() OVER (ORDER BY lowest_price ASC) AS price_rank,
DENSE_RANK() OVER (ORDER BY lowest_price ASC) AS price_dense_rank,
ROW_NUMBER() OVER (ORDER BY lowest_price ASC) AS price_row_number
FROM mytable
WHERE lowest_price BETWEEN 200000 AND 500000;