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

+----+-------+
| Id | Score |
+----+-------+
| 1 | 3.50 |
| 2 | 3.65 |
| 3 | 4.00 |
| 4 | 3.85 |
| 5 | 4.00 |
| 6 | 3.65 |
+----+-------+
例如,根据上述给定的 Scores 表,你的查询应该返回(按分数从高到低排列):

+-------+------+
| Score | Rank |
+-------+------+
| 4.00 | 1 |
| 4.00 | 1 |
| 3.85 | 2 |
| 3.65 | 3 |
| 3.65 | 3 |
| 3.50 | 4 |
+-------+------+

来源:力扣(LeetCode)

SELECT Score, (SELECT count(DISTINCT score) FROM Scores WHERE score >= s.score) AS Rank FROM Scores s ORDER BY Score DESC ;

MYSQL分数排名的更多相关文章

  1. MySQL分数排名同分并列与不并列查询

    Scores表 | Id | Score | | 3.50 | | 3.65 | | 4.00 | | 3.85 | | 4.00 | | 3.65 | 并列 | Score | Rank | | | ...

  2. 178. 分数排名 + MySql + RANK() OVER

    178. 分数排名 LeetCode_MySql_178 题目描述 题解分析 排名函数 DENSE_RANK().如果使用 DENSE_RANK() 进行排名会得到:1,1,2,3,4. RANK() ...

  3. mysql查询之分数排名

    编写一个 SQL 查询来实现分数排名.如果两个分数相同,则两个分数排名(Rank)相同 +----+-------+ | Id | Score | +----+-------+ | 1 | 3.50 ...

  4. [SQL]LeetCode178. 分数排名 | Rank Scores

    Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ra ...

  5. mysql计算排名 转

    from :http://www.cnblogs.com/aeiou/p/5719396.html http://www.cnblogs.com/zengguowang/p/5541431.html ...

  6. MySQL实现排名并查询指定用户排名功能,并列排名功能

    MySQL实现排名并查询指定用户排名功能,并列排名功能 表结构: CREATE TABLE test.testsort ( id int(11) NOT NULL AUTO_INCREMENT, ui ...

  7. LeetCode(数据库):分数排名

    ,)); Truncate table Scores; ', '3.5'); ', '3.65'); ', '4.0'); ', '3.85'); ', '4.0'); ', '3.65'); 编写一 ...

  8. LeetCode:178.分数排名

    题目链接:https://leetcode-cn.com/problems/rank-scores/ 题目 编写一个 SQL 查询来实现分数排名.如果两个分数相同,则两个分数排名(Rank)相同.请注 ...

  9. mysql成绩排名

    关于mysql成绩排名,网上大部分只是order by简单排序,忽略了成绩相同并列名次的问题. 定义了一个表score结构为:

随机推荐

  1. Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: ERR invalid longitude,latitude pair 111.110000,111.230000

    io.lettuce.core.RedisCommandExecutionException: ERR invalid longitude,latitude pair 111.110000,111.2 ...

  2. Python之字符串搜索和替换

    简单直接使用 str.replace() text="zzy is a beautiful boy" print(text.replace("boy",&quo ...

  3. myEclipse 搭建 Spring boot+myBatis+maven 项目流程

    1.新建一个工程 new-->maven project-->next-->next-->在filter中搜索webapp-->group id.Artifact id- ...

  4. ionic2(3) 密码键盘组件 ionic2-pincode-input 使用

    1.效果展示: 2.安装: npm install ionic2-pincode-input --save 3.app.module.ts配置 app.module.ts import { NgMod ...

  5. 【sql】leetcode习题 (共 42 题)

    [175]Combine Two Tables (2018年11月23日,开始集中review基础) Table: Person +-------------+---------+ | Column ...

  6. Async Clipboard AP

    转自奇舞周刊,个人学习记录,侵权删 编者按:本文作者李松峰,资深技术图书译者,翻译出版过40余部技术及交互设计专著,现任360奇舞团高级前端开发工程师,360前端技术委员会委员.W3C AC代表 如果 ...

  7. Windows——关于Word2016/2019提示需要修复问题处理

    一.问题描述 打开Word提示 很抱歉此功能看似已中断,并需要修复.请使用Windows控制面板中的“程序和功能”选项修复Microsoft Office. 二.解决方法 运行 regedit 进入注 ...

  8. 【错误总结】Component template should contain exactly one root element. If you are using v-if on multiple elements, use v-else-if to chain them instead.

    大致意思是因为模板里面应该包含一个根元素,使用组件的时候应该用div或p标签包起来

  9. leetcode-163周赛-1263-推箱子*

    题目描述: 自己的提交: class Solution: def minPushBox(self, grid: List[List[str]]) -> int: driction = [(0,1 ...

  10. SnowFlakeId 分布式雪花id算法

    package com.jn.baseservice.utils; import com.jn.baseservice.common.Number; import lombok.Getter; imp ...