首页 > 开发 > 综合 > 正文

178. Rank Scores#1

2024-07-21 02:51:18
字体:
来源:转载
供稿:网友

Solution#1

# Write your MySQL query statement belowSELECT Score, (SELECT COUNT(DISTINCT Score) FROM Scores WHERE S.Score <= Score) Rank From Scores S ORDER BY Score DESC

Solution#2

# Write your MySQL query statement belowSELECT s.Score, count(distinct t.Score) RankFrom Scores s JOIN Scores t ON s.Score <= t.ScoreGROUP BY s.IdORDER BY s.Score DESC

第一种方法更快 第二种方法中,必须加上GROUP BY,否则count后的结果中会有null和0;


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表