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. NOI 2002 贪吃的九头龙

    树形dp #include<bits/stdc++.h> #define N 305 using namespace std; struct LEB{ int to,nxt,w; }e[N ...

  2. 洛谷P4774 屠龙勇士

    啊我死了. 肝了三天的毒瘤题......他们考场怎么A的啊. 大意: 给你若干个形如 的方程组,求最小整数解. 嗯......exCRT的变式. 考虑把前面的系数化掉: 然后就是exCRT板子了. 我 ...

  3. 扩展方法、委托和Lambda

    举例演化Lambda string[] names ={"Burke", "Connor", "Frank", "Everett& ...

  4. margin纵向重叠

    速记: 如p的纵向 margin 是 16px,那么两个之间纵向的距离是多少?-- 按常理来说应该是 16 + 16 = 32px,但是答案仍然是 16px. 因为纵向的 margin 是会重叠的,如 ...

  5. python 二维数组读入

    study from : https://www.cnblogs.com/reaptomorrow-flydream/p/9613847.html python 二维数组键盘输入 1 m = int( ...

  6. 向redis中添加删除list列表

    转: 向redis中添加删除list列表 2018年04月18日 15:44:54 luo_yu_1106 阅读数:4082   一.添加 向redis中添加队列有两种方式 1.lpush l是lef ...

  7. struts2 contextMap

    一.contextMap中的数据操作 root根:List 元素1 元素2 元素3 元素4 元素5 contextMap:Map key value application Map key value ...

  8. Codeforces Round #529 (Div. 3) F.Make It Connected

    传送门 题意: 有 n 个顶点,每个顶点有个花费 a[ i ],连接顶点 u,v 需要花费 a[v]+a[u]的代价. 有 m 个特殊边,每条边有三个参数 u,v,w 代表的意思是连接 u,v 的花费 ...

  9. JS学习笔记Day4

    一.什么是函数 将反复使用的功能代码,封装成一独立的模块,这个模块叫做函数 二.封装函数的好处 1.一次封装,多次使用 2.使程序可控 三.函数的分类:内置()函数和自定义函数 四.函数的数据类型(f ...

  10. AT2165 Median Pyramid Hard 二分答案 脑洞题

    无论再来多少次也不可能想到的写法. 二分一个最小的顶端值\(k\),大于设为\(1\)小于等于设为\(0\),可以证猜出来(你跟我说这可以?)如果存在两个连在一起的0/1那么它们会一直往上跑,还可以很 ...