πŸ”₯ PS(Problem Solving) πŸ”₯/SQL

[SQL] Leetcode | 178. Rank Scores

dar0m! 2021. 7. 8. 22:31

178. Rank Scores

Medium
 

Rank Scores - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

 

μˆœμœ„ ν•¨μˆ˜ DENSE_RANK()

select score, `rank`
from (
    select score, DENSE_RANK() over (order by Score desc) as `rank`
    from Scores
) score_rank
order by `rank`;
  • 176 Second Highest Salary λ₯Ό ν’€κ³  λ‚˜λ‹ˆ μ‰½κ²Œ ν’€ 수 있던 문제 μ˜€λ‹€.
  • 그리고 이 λ¬Έμ œμ—μ„œλŠ” μΉœμ ˆν•˜κ²Œλ„ μ˜ˆμ•½μ–΄λ₯Ό νƒˆμΆœν•˜λ €λ©΄ μ–΄νΌμŠ€νŠΈλ‘œν”Ό(`)λ₯Ό μ‚¬μš©ν•˜λΌλŠ” νŒλ„ μ€€λ‹€.
  • Important Note: For MySQL solutions, to escape reserved words used as column names, you can use an apostrophe before and after the keyword. For example Rank.