178.Rank_Scores
来源:互联网 发布:张靓颖 冯轲 知乎 编辑:程序博客网 时间:2024/05/22 03:46
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.
#+----+-------+#| 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 |#+-------+------+
sql脚本
SELECT Score, @rank := @rank + (@prev <> (@prev := Score)) RankFROM Scores, (SELECT @rank := 0, @prev := -1) initORDER BY Score DESC
阅读全文
0 0
- 178.Rank_Scores
- leetcode 178. Rank Scores
- Leetcode 178. Rank Scores
- 178. Rank Scores#1
- 178. Rank Scores
- leetcode-database-178.Rank Scores
- leetcode-database-178. Rank Scores
- 【leetcode Database】178. Rank Scores
- 178.God helps those who help themselves. 自助者天助
- 178.Graph Valid Tree-图是否是树(中等题)
- 178.n1-使用自定义MyBitmapUtils,不使用xUtils的BitmapUtils加载图片
- MySQL中变量的用法——LeetCode 178. Rank Scores
- 178.All the database users are presently connected to the database instance and working. The HR user
- js 验证手机号、邮箱、数字、文件后缀
- java 动态代理
- JAVA面向对象3:static关键字和内部类
- 蓝桥杯篇4
- 剑指offer面试题[17]-合并两个排序的链表
- 178.Rank_Scores
- 机器学习之numpy和matplotlib学习(八)
- 无题
- 快速了解Jmeter
- PAT 甲级 1013. Battle Over Cities
- mybatis的二级缓存
- 提取docx转为txt后的文件内容
- NO.1 BF(Brute Froce),MP
- 高效率科研神器——小软件、大能量