cjql / algorithm

https://cjql.github.io/algorithm/
1 stars 1 forks source link

sql: rank-scores #13

Open cjql opened 4 years ago

cjql commented 4 years ago

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

SELECT
  Score,
  @rank := @rank + (@prev <> (@prev := Score)) Rank
FROM
  Scores,
  (SELECT @rank := 0, @prev := -1) init
ORDER BY Score desc