-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
178.cpp
17 lines (17 loc) · 915 Bytes
/
178.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
__________________________________________________________________________________________________
SELECT Score,
(SELECT COUNT(DISTINCT Score) FROM Scores WHERE Score >= s.Score) Rank
FROM Scores s ORDER BY Score DESC;
__________________________________________________________________________________________________
SELECT Score,
(SELECT COUNT(*) FROM (SELECT DISTINCT Score s FROM Scores) t WHERE s >= Score) Rank
FROM Scores ORDER BY Score DESC;
__________________________________________________________________________________________________
SELECT s.Score, COUNT(DISTINCT t.Score) Rank
FROM Scores s JOIN Scores t ON s.Score <= t.Score
GROUP BY s.Id ORDER BY s.Score DESC;
__________________________________________________________________________________________________
SELECT Score,
@rank := @rank + (@pre <> (@pre := Score)) Rank
FROM Scores, (SELECT @rank := 0, @pre := -1) INIT
ORDER BY Score DESC;