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.

+----+-------+
| Id | Score |
+----+-------+
| 1 | 3.50 |
| 2 | 3.65 |
| 3 | 4.00 |
| 4 | 3.85 |
| 5 | 4.00 |
| 6 | 3.65 |
+----+-------+

For example, given the above Scores table, your query should generate the following report (order by highest score):

+-------+------+
| Score | Rank |
+-------+------+
| 4.00 | 1 |
| 4.00 | 1 |
| 3.85 | 2 |
| 3.65 | 3 |
| 3.65 | 3 |
| 3.50 | 4 |
+-------+------+
# Write your MySQL query statement below
select Score, Rank from
(
select Score,
@rank := @rank + if(@prevSc=Score, 0, 1) as Rank,
@prevSc := Score
from (select @prevSc := null) x, (select @rank := 0) y,
(select * from Scores order by Score desc) z
) a;

  

最新文章

  1. C# 实现软件的重启
  2. Nginx跨域配置方法
  3. JavaScript学习08 Cookie对象
  4. java eclipse打jar包和执行jar中的main函数
  5. yum -y list java* 查看当前java的版本
  6. Java Hour 54 Spring Framework 1
  7. .NET P****** CMS 逆向工程
  8. jacob 操作word
  9. MVC验证12-使用DataAnnotationsExtensions对整型、邮件、最小值、文件类型、Url地址等验证
  10. 将DataTable内容导出到Excel表格的两种方法
  11. Caffe、TensorFlow、MXnet三个开源库对比
  12. 【BZOJ3277】串(后缀自动机)
  13. Unity3D判断角色对敌人是否可见
  14. Windows系统版本判定那些事儿
  15. Centos7配置TiDB监控
  16. vue moment库格式化处理后端传的日期
  17. node调试工具--nodemon
  18. MySQL安装脚本最佳实践
  19. 第一次spring冲刺第3、4天
  20. php的初步了解

热门文章

  1. javascript QUnit 单元测试
  2. java 无法找到main类解决办法
  3. 展讯NAND Flash高级教程【转】
  4. Socket 通信原理(Android客户端和服务器以TCP&&UDP方式互通)
  5. Docker入门命令
  6. CF 314C Sereja and Subsequences(树状数组)
  7. grep/awk/sed 或者 并且 否定
  8. Qt之重启应用程序
  9. iOS富文本(三)深入使用Text Kit
  10. HDU 2084 数塔