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 ...
随机推荐
- 2018"百度之星"程序设计大赛 - 资格赛hdu6349三原色(最小生成树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6349 题目: 三原色图 Time Limit: 1500/1000 MS (Java/Others) ...
- POJ--2104 K-th Number (主席树模版题)
题目链接 求区间第k大 #include<iostream> #include<cstring> #include<algorithm> #include<v ...
- 1.Ubuntu系统与vmware虚拟机的安装与使用
1.下载Ubuntu的镜像文件 种子文件的下载页面的链接:https://www.ubuntu.com/download/alternative-downloads 可以去选择版本的桌面版(Deskt ...
- Python基础-元组、列表、字典
元组tuple 元组被称为只读列表,即数据可以被查询,但不能被修改,所以,字符串的切片操作同样适用于元组.例:(1,2,3)("a","b","c&q ...
- django基于存储在前端的token用户认证
一.前提 首先是这个代码基于前后端分离的API,我们用了django的framework模块,帮助我们快速的编写restful规则的接口 前端token原理: 把(token=加密后的字符串,key= ...
- 第十九节,使用RNN实现一个退位减法器
退位减法具有RNN的特性,即输入的两个数相减时,一旦发生退位运算,需要将中间状态保存起来,当高位的数传入时将退位标志一并传入参与计算. 我们在做减法运算时候,把减数和被减数转换为二进制然后进行运算.我 ...
- HTML学习笔记Day15
一.CSS3渐变 (一).CSS3渐变(gradient)可以让你在两个或多个指定的颜色之间显示平稳的过度:渐变效果比使用图片在放大时看起来效果更好,因为渐变(gradient)是由浏览器生成的 1. ...
- Linux/Unix系统QA
Q1:Ext3的三种日志记录方式 1 data=writeback 方式data=writeback方式下,ext3根本不执行任何形式的数据日志记录,提供给您的是和在XFS,JFS和 ReiserFS ...
- (map)水果 hdu1263
水果 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...
- go框架gin的使用
我们在用http的时候一般都会用一些web框架来进行开发,gin就是这样的一个框架,它有哪些特点呢 一:gin特点 1.性能优秀2.基于官方的net/http的有限封装3.方便 灵活的中间件4.数据绑 ...