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. 算法练习:求字符串的最长重复子串(Java实现)

    1. 求字符串的最长重复子串 例如:aaaaaaaaabbbbcccaaassscvvv这里面的最长重复子串为aaaaaaaaa 算法思路:算法时间复杂度(O(n)) 1. 将这一个字符串先转成cha ...

  2. 初入react-redux (基于webpack babel的react应用框架)

    react这么热门的框架也不介绍了,redux是一个单项数据流的小框架,当然不只配合react,它起初是为react而配的,现在面向所有了,比如ng-redux的项目.redux做为react的标准搭 ...

  3. js 读取包含特殊字符的属性值

    在JS中对象的属性可以通过两种方式访问:object.property和object["property"]. 包含特殊字符的属性只能以此方式访问: object["pr ...

  4. bzoj2086 Blocks

    题目链接 题面 思路 可以发现其实就是询问一个最长的区间,使得这个区间的平均数大于等于k.所以将区间内所有数字减去k,然后做一遍前缀和.只要是前缀和之差大于等于0的区间.就是满足条件的. 所以现在问题 ...

  5. HTTP属性管理器 初探

      1)HTTP Cache Manager 2)HTTP Cookie 管理器 3)HTTP 信息头管理器 4)HTTP 授权管理器 5)HTTP 请求默认值 为什么会有这些http属性的配置元件? ...

  6. Day019--Python--反射

    1. issubclass, type, isinstance issubclass 判断XXX类是否是XXX类的子类 type 给出XXX的数据类型. 给出创建这个对象的类 isinstance 判 ...

  7. 我眼中的正则化(Regularization)

    警告:本文为小白入门学习笔记 在机器学习的过程中我们常常会遇到过拟合和欠拟合的现象,就如西瓜书中一个例子: 如果训练样本是带有锯齿的树叶,过拟合会认为树叶一定要带有锯齿,否则就不是树叶.而欠拟合则认为 ...

  8. Luogu P2292 [HNOI2004]L语言

    题目链接 \(Click\) \(Here\) 好久没写\(DP\)了真是水平下降不少,一眼把这个题搞成贪心了,然后一发交上只有\(37\)分\(QwQ\) 这个题好像还可以\(AC\)自动机胡搞?不 ...

  9. MySQL mysqldump 导入/导出 结构&数据&存储过程&函数&事件&触发器

    ———————————————-库操作———————————————-1.①导出一个库结构 mysqldump -d dbname -u root -p > xxx.sql ②导出多个库结构 m ...

  10. 微信小程序:下拉刷新

    下拉刷新 1.需要在json文件中,设置"enablePullDownRefresh": true,表示该页面使用下拉刷新 2.在微信内置函数onPullDownRefresh中进 ...