178. Rank Scores

旧城等待, 2022-04-24 15:02 294阅读 0赞
  1. Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ranking. Note that after a tie, the next ranking number should be the next consecutive integer value. In other words, there should be no "holes" between ranks.
  2. +----+-------+
  3. | Id | Score |
  4. +----+-------+
  5. | 1 | 3.50 |
  6. | 2 | 3.65 |
  7. | 3 | 4.00 |
  8. | 4 | 3.85 |
  9. | 5 | 4.00 |
  10. | 6 | 3.65 |
  11. +----+-------+
  12. For example, given the above Scores table, your query should generate the following report (order by highest score):
  13. +-------+------+
  14. | Score | Rank |
  15. +-------+------+
  16. | 4.00 | 1 |
  17. | 4.00 | 1 |
  18. | 3.85 | 2 |
  19. | 3.65 | 3 |
  20. | 3.65 | 3 |
  21. | 3.50 | 4 |
  22. +-------+------+

个人觉得本题没有意义,这样排名在常规后端语言如JAVA中很容易实现。

具体解答参照MySQL中变量的用法——LeetCode 178. Rank Scores

发表评论

表情:
评论列表 (有 0 条评论,294人围观)

还没有评论,来说两句吧...

相关阅读

    相关 178. 分数排名

    SQL架构 编写一个 SQL 查询来实现分数排名。 如果两个分数相同,则两个分数排名(Rank)相同。请注意,平分后的下一个名次应该是下一个连续的整数值。换句话说,名次之间

    相关 得分(Score)

    给出一个由O和X组成的串(长度为1~80),统计得分。每个O的得分为目前连续出现的O的个数,X的得分为0。 例如:OOXXOXXOOO的得分为1+2+0+0+1+0+0+1

    相关 178. 分数排名

    编写一个 SQL 查询来实现分数排名。 如果两个分数相同,则两个分数排名(Rank)相同。请注意,平分后的下一个名次应该是下一个连续的整数值。换句话说,名次之间不应该有“间隔

    相关 sql 178. 分数排名

    编写一个 SQL 查询来实现分数排名。如果两个分数相同,则两个分数排名(Rank)相同。请注意,平分后的下一个名次应该是下一个连续的整数值。换句话说,名次之间不应该有“间隔”。