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. Ubuntu Server 18.04 网络设置不生效的解决

    在Ubuntu18.04中,传统的配置/etc/network/interfaces已无用https://www.cnblogs.com/dunitian/p/6658578.html 新方法:修改 ...

  2. spring activemq 整合

    创建maven项目 项目目录结构为 首先配置相关maven依赖 <!-- 版本管理 --> <properties> <springframework>4.1.8. ...

  3. 解题:CF622F The Sum of the k-th Powers

    题面 TJOI2018出CF原题弱化版是不是有点太过分了?对,就是 TJOI2018 教科书般的亵渎 然而我这个问题只会那个题的范围的m^3做法 回忆一下1到n求和是二次的,平方求和公式是三次的,立方 ...

  4. (转)从一道面试题彻底搞懂hashCode与equals的作用与区别及应当注意的细节

    背景:学习java的基础知识,每次回顾,总会有不同的认识.该文系转载 最近去面试了几家公司,被问到hashCode的作用,虽然回答出来了,但是自己还是对hashCode和equals的作用一知半解的, ...

  5. mciSendString 多线程播放多首音乐 & 注意事项

    昨天晚上遇到一个问题: 使用 mciSendString  控制播放多首音乐的时候,出现最后一次播放的音乐无法通过 mciSendString ("close mp3") 关闭音乐 ...

  6. IE jQuery ajax 请求缓存问题

    我最近在IE下测试开发我们的系统,经常出现改过的jsp页面,刷新IE后也不能显示,这就是IE的缓存问题,查了一下百度,说是IE9在ajax进行请求时,如果两次请求url相同,则不会请求服务器,而是从缓 ...

  7. haploview出现“results file must contain a snp column”的解决方法

    将plink文件用“--recode HV ”的参数生成即可 /software/plink --file yourfile --recode HV --snps-only just-acgt --o ...

  8. rm刷机 root

    http://www.miui.com/download-290.html http://www.miui.com/shuaji-329.html    小米稳定版 不可以root 只有升级到上面的开 ...

  9. 计算机基础:计算机网络-socket编程

    来源:mooc大学华南理工大学计算机网络课程 chapter6 代码:https://github.com/NeilKeats/SocketDemo/commit/5f3a795250a9533910 ...

  10. parallels tools 安装

    │ - kernel-devel-2.6.32-358.el6.x86_64 │ │ - dkms