๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ”ฅ PS(Problem Solving) ๐Ÿ”ฅ/SQL

[SQL] Leetcode | 178. Rank Scores

by dar0m! 2021. 7. 8.

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.

๋Œ“๊ธ€