0
1

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 5 years have passed since last update.

Mysqlでスコア順の順位を簡単に表示する

Posted at

Mysqlの得点テーブルから、特定の順位の得点を抜き出したい

と言う要望があったので、簡単に取得できる方法を考えてみた。

対象のテーブルにsocre順の順位をつける

set @rank=0;select user_id,score,rank from (select user_id,score,(@rank:=@rank+1) as rank from user_scores order by score desc) a where rank in (1,10,100,500,1000,1500,3000,5000,8000);
Add Comment

対象の順位の得点のみ取得する

set @rank=0;select user_id,score,rank from (select user_id,score,(@rank:=@rank+1) as rank from user_scores order by score desc) a where rank in (1,10,100,1000,10000);
Add Comment
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?