题目4:MySQL----------Rank Scores
来源:互联网 发布:ubuntu不能创建文件夹 编辑:程序博客网 时间:2024/05/22 00:12
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 |+-------+------+
题目解答:
一、
SELECT Score, (SELECT count(*) FROM (SELECT distinct Score s FROM Scores) tem WHERE s >= Score) RankFROM ScoresORDER BY Score desc;
二、
# Write your MySQL query statement belowSELECT Scores.Score, COUNT(Ranking.Score) AS RANK FROM Scores , ( SELECT DISTINCT Score FROM Scores ) Ranking WHERE Scores.Score <= Ranking.Score GROUP BY Scores.Id, Scores.Score ORDER BY Scores.Score DESC;
0 0
- 题目4:MySQL----------Rank Scores
- MySQL-Rank Scores
- Rank Scores
- Rank Scores
- Rank Scores
- Rank Scores
- Rank Scores
- LeetCode | Rank Scores
- leetcode 178 Rank Scores
- [LeetCode] Rank Scores - SQL
- Leetcode: Rank Scores
- [LeetCode][Database]Rank Scores
- LeetCode Rank Scores
- LeetCode_OJ【178】Rank Scores
- Database LeetCode Rank Scores
- leetcode 178. Rank Scores
- Leetcode 178. Rank Scores
- 【leetcode】Rank Scores
- if for while util case select 参数
- 点击超链接,不跳转界面
- android中子线程更新UI的方式浅析
- [数字图像处理]频域滤波(2)--高通滤波器,带阻滤波器与陷波滤波器
- github诞生记
- 题目4:MySQL----------Rank Scores
- 题目5:MySQL----------Consecutive Numbers
- 进制转换(itoa函数的使用)
- c语言学习笔记 之调用dll动态库
- Python模块卸载
- java中垃圾收集器的重点
- 黑马程序员——java集合框架
- C学习笔记(五)字符输入\输出
- 整型变量