sql -leetcode 178. Rank Scores
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的更多相关文章
- 【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 ...
- 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 ...
- [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 ...
- 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 ...
- 178. Rank Scores - database - 178. Rank Scores (Oracle)
题目链接 https://leetcode.com/problems/rank-scores/description/ 题意:对所有的分数按照降序进行排序,查询出分数和排名,排名相同的输出相同名 ...
- 178. Rank Scores
问题描述 解决方案 select sc.Score, (select count(*) from (select distinct Score from Scores ) ds where ds.Sc ...
- [LeetCode] Rank Scores 分数排行
Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ra ...
- [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 ...
- [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 ...
随机推荐
- os模块总结
学了忘,忘了学,忘了就来看一下...唯一进步的就是这次学的比上次更快了- - 最常用的几个: os.getcwd() # os.path.abspath(os.path.dirname(__fil ...
- ImageMagick: 6.8.3 升级到 6.8.9 遇到的问题
最终还是决定升级到目前最新版:6.8.9,不知何时才真正明白为什么现在都是java8,但还是有很多软件系统使用在java5上. 虽然新版本能带来各种好处,但现实中不能忽略一个问题:原来的代码很可能无法 ...
- jQuery 传递对象参数到Spring Controller
当jQuery 发送ajax请求需要传递多个参数时,如果参数过多,Controller接收参数时就需要定义多个参数,这样接口方法会比较长,也不方便.Spring可以传递对象参数,将你需要的所有查询条件 ...
- TODO monkey笔记,PC端执行和手机端执行
微博不给力啊 吞我笔记,还好我有txt... 1.环境准备:安装Android sdk, 配置环境变量:platfrom_tools,tools,aapt;java:2.查询当前apk信息: aapt ...
- 用python画三角函数
Pyplot http://www.labri.fr/perso/nrougier/teaching/matplotlib/ pyplot提供了一个方便的matplotlib基于对象库的借口,是模仿了 ...
- 关于python类变量和实例变量
今天在看python的类和实例的时候,突然发现了一个以前遗漏的点,也就是类变量和实例变量.首先需要理解一下类变量和实例变量的概念. 类全局变量:在类中定义,对类和由类生成的实例生效,如果通过方法对类变 ...
- (find) nyoj5-Binary String Matching
5-Binary String Matching 内存限制:64MB 时间限制:3000ms 特判: No通过数:232 提交数:458 难度:3 题目描述: Given two strings A ...
- Druid数据源配置
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-met ...
- IDEA常用快捷键整理(Mac OS X版本)
最近eclipse把我弄疯了!各种提示没有!烦,果断用了IDEA. 一.前提 IDEA版本:IntelliJ IDEA 15.0.3 Keymaps:Mac OS X 二.视图切换快捷键 1.cmd ...
- ELK 安装与基本配置(一)
对于日志来说,最常见的需求就是收集.存储.查询.展示,开源社区正好有相对应的开源项目:logstash(收集).elasticsearch(存储+搜索).kibana(展示),我们将这三个组合起来的技 ...