[LeetCode] 178. Rank Scores

주연·2023년 5월 8일
0

SQL 문제 풀이

목록 보기
26/28
post-thumbnail

문제

https://leetcode.com/problems/rank-scores/description/

score 내림차순으로 rank,
같은 순위가 있다면 그 다음은 연속적인 수로 (ex. 122234)

풀이

SELECT score
    , DENSE_RANK() OVER (ORDER BY score DESC) AS Rank
FROM Scores

이렇게 했는데
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'rank FROM Scores' at line 3
이런 오류가 자꾸 뜬다.

왜인가 했더니 rank라는 함수가 있어서 안된다고 함...
그래서 난 그냥 뭐야~이러고 MS SQL Server에서 돌렸더니 여기서는 되네..?

mysql에서 돌릴려면

SELECT score
    , DENSE_RANK() OVER (ORDER BY score DESC) AS 'Rank'
FROM Scores

Rank에 따옴표만 붙여주면 된다!

profile
공부 기록

0개의 댓글