1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

100日でSQLの達人になる@LeetCode! Day62 <復習問題:DENS_RANKで順位を付ける>

Posted at

178. Rank Scores (問題レベル: Medium)無課金

今日もリハビリでLeetCode Curated SQL 70とは違う問題。

今日の問題はこれ。
ばらばらに並んでいるスコアのリストを降順に並べて、順位を付けるというシンプルな問題。
順位は同じ順位なら同順を付けて、順位はスキップしない。
つまり、1位、1位、3位ではなくて1位、1位、2位と付けるという方法。

ポイントはDay44で学習したDENSE_RANKを使うだった。

提出したのはこちら。

SQL Server
SELECT score, DENSE_RANK() OVER(ORDER BY score DESC) AS rank
  FROM scores

Discussを覗いて見るとMySQLでは、AS rankがだめなようで

MySQL
SELECT Score, DENSE_RANK() OVER(ORDER BY score DESC) `rank`
  FROM scores

と記載する必要があるということ。rankが予約語だからかな?

  • LeetCodeの問題は、MS SQL Serverで解いています。
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?