Score 很好得到: select Score from Scores order by Score desc;

要得到rank, 可以通过比较比当前Score 大的Score 的个数得到:

select Score, (select count(distinct Score) from Scores where Score>=s.Score) Rank where Scores s order by Score desc;

  

或者:

select s.Score ,count(distinct t.Score)Rank from Scores s join Scores t on s.Score<=t.Score

  得到join 两个表,

{"headers": ["Score", "Score"], "values": [[3.50, 3.50], [3.50, 3.65], [3.65, 3.65], [3.65, 3.65], [3.50, 4.00], [3.65, 4.00], [4.00, 4.00], [3.85, 4.00], [4.00, 4.00], [3.65, 4.00], [3.50, 3.85], [3.65, 3.85], [3.85, 3.85], [3.65, 3.85], [3.50, 4.00], [3.65, 4.00], [4.00, 4.00], [3.85, 4.00], [4.00, 4.00], [3.65, 4.00], [3.50, 3.65], [3.65, 3.65], [3.65, 3.65]]}

按s.Id 聚在一起:
select s.Score ,count(distinct t.Score)Rank from Scores s join Scores t on s.Score<=t.Score
group by s.Id
order by s.Score desc

  

												

sql -leetcode 178. Rank Scores的更多相关文章

  1. 【SQL】178. Rank Scores

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

  2. MySQL中变量的用法——LeetCode 178. Rank Scores

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

  3. [LeetCode#178]Rank Scores

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

  4. LeetCode Database: Rank Scores

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

  5. 178. Rank Scores - database - 178. Rank Scores (Oracle)

    题目链接    https://leetcode.com/problems/rank-scores/description/ 题意:对所有的分数按照降序进行排序,查询出分数和排名,排名相同的输出相同名 ...

  6. 178. Rank Scores

    问题描述 解决方案 select sc.Score, (select count(*) from (select distinct Score from Scores ) ds where ds.Sc ...

  7. [LeetCode] Rank Scores 分数排行

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

  8. [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 ...

  9. [LeetCode] Rank Scores -- 数据库知识(mysql)

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

随机推荐

  1. 整车CAN网络介绍

    CAN(Controller Area Network)控制器局域网络,CAN网络在早期的整车应用中以BCM(车身控制器)为控制中心,主要是车身零部件(雨刮/大灯/车窗…),智能硬件较少,所以早期的正 ...

  2. nodejs的某些api~(一)node的流1

    根据心情整理一些node的api~ 今天第一篇,node的流:node的流比较重要,node的流存在于node的各个模块,包括输入输出流,stdin,stout.fs读取流,zlib流,crypto流 ...

  3. Python中的实例方法、classmethod和staticmethod的区别

    class NewsPaper(object): # 类属性 __print_times = 0 # 下划线表示私有属性 # 实例方法 def __init__(self, title, conten ...

  4. UOJ#418. 【集训队作业2018】三角形

    #418. [集训队作业2018]三角形 和三角形没有关系 只要知道儿子放置的顺序,就可以直接模拟了 记录历史最大值 用一个pair(a,b):之后加上a个,期间最大值为增加b个 合并? A1+A2= ...

  5. 【洛谷P2127】序列排序

    题目大意:给定一个长度为 N 的序列,序列中的数两两不相同,每次可以交换序列中任意两个数,代价为这两个数的和,问将序列调整为升序,最少的代价是多少. 题解:考虑这个问题的一个子问题,这个序列为 N 的 ...

  6. 【清北学堂2018-刷题冲刺】Contest 6

    Task 1:子集 [问题描述]  若一个集合S中任意两个元素x和y,都满足x⊕y<min⁡(x, y) ,则称集合S是"好的".其中⊕为按位异或运算符.现在给定一个大小为n ...

  7. 离线提取目标机hash

    ##看了大佬的文章学习到一个姿势在此将其记录一下复现过程 github项目地址:https://github.com/SecureAuthCorp/impacket.git python setup ...

  8. Go-day05

    今日概要: 1. 结构体和方法 2. 接口 一.go中的struct 1. 用来自定义复杂数据结构 2. struct里面可以包含多个字段(属性) 3. struct类型可以定义方法,注意和函数的区分 ...

  9. xlrd(excel导入mysql数据库)

    一.xlrd模块: python 对 excel 文件进行读操作 1.下载xlrd 并安装 http://pypi.python.org/pypi/xlrd wget https://pypi.pyt ...

  10. Java 读取propertoes文件

    我一直不懂,Java里面的路径是咋样的,怎么找到我的资源文件? 直到我看到了这篇文件,写的是真棒.这篇文章  看完之后,豁然开朗的感觉 下面做些笔记,首先,Java有一个targer文件,下面有一个c ...