当前位置:网站首页>Leetcode MySQL database topic 178
Leetcode MySQL database topic 178
2022-06-29 09:58:00 【Water like ice】
178. Rank Scores
1、 Questions and answers
Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ranking. Note that after a tie, the next ranking number should be the next consecutive integer value. In other words, there should be no “holes” between ranks.
To write SQL Query to sort scores . If two scores are equal , Then both should have the same ranking . Please note that , After equality , The next rank number should be the next consecutive integer value . let me put it another way , Equal scores juxtapose .
Table:Scores
+----+-------+
| Id | Score |
+----+-------+
| 1 | 3.50 |
| 2 | 3.65 |
| 3 | 4.00 |
| 4 | 3.85 |
| 5 | 4.00 |
| 6 | 3.65 |
+----+-------+For example, given the above
Scorestable, your query should generate the following report (order by highest score):
for example , Give the above “Scores” surface , Your query should generate the following report ( Sort by highest score )
+-------+------+
| Score | Rank |
+-------+------+
| 4.00 | 1 |
| 4.00 | 1 |
| 3.85 | 2 |
| 3.65 | 3 |
| 3.65 | 3 |
| 3.50 | 4 |
+-------+------+ answer : select
Score,
(select count(distinct b.Score) from scores b where b.Score >= s.Score) as Rank
from scores s
order by Score desc
2、 Summary of knowledge points
Verification steps :
Create and insert tables scorescreate table scores(
Id int NULL,
Score double NULL
);
insert into scores
values(1,3.5),(2,3.65),(3,4.00),(4,3.85),(5,4.00),(6,3.65);
Execute the answer :
+-------+------+
| Score | Rank |
+-------+------+
| 4 | 1 |
| 4 | 1 |
| 3.85 | 2 |
| 3.65 | 3 |
| 3.65 | 3 |
| 3.5 | 4 |
+-------+------+
6 rows in set (0.00 sec)Knowledge point :
- Subquery and where Screening
select count( distinct id ) from table_nameCalculation talbebname In the table id How many different records
边栏推荐
- Fabrication d'une calculatrice d'addition simple basée sur pyqt5 et Qt Designer
- IPC(进程间通信)之管道详解
- Official STM32 chip package download address stm32f10x stm32f40x Download
- 证券账号开户安全吗?是靠谱的吗?
- F5 BIG-IP iControl REST命令执行(CVE-2022-1388)
- 自定义mvc框架实现
- 2020-9-14 广告系统入门
- 指针函数和函数指针
- CROSSFORMER: A VERSATILE VISION TRANSFORMER BASED ON CROSS-SCALE ATTENTION
- Data visualization: the four quadrants of data visualization teach you to correctly apply icons
猜你喜欢

linux环境下安装配置redis,并设置开机自启动

装饰器模式的应用,包装ServletRequest,增加addParameter方法

力扣94二叉树的中序遍历

Student增删gaih

Fully Automated Gross Tumor Volume Delineation From PET in Head and Neck Cancer Using Deep Learning

Hystrix熔断器:服务熔断与服务降级

Segmentation of Head and Neck Tumours Using Modified U-net

Fully Automated Delineation of Gross Tumor Volume for Head and Neck Cancer on PET-CT Using Deep Lear

Automatic 3D Detection and Segmentation of Head and Neck Cancer from MRI Data.

Custom MVC framework implementation
随机推荐
2020-09-21 referer字符串切分 boost gateway代码组织层次
ImageView图片填充问题
CROSSFORMER: A VERSATILE VISION TRANSFORMER BASED ON CROSS-SCALE ATTENTION
cenos7下搭建LAMP环境
Fully Automated Gross Tumor Volume Delineation From PET in Head and Neck Cancer Using Deep Learning
基於PyQt5和Qt Designer的簡易加法計算器的制作
语言特性
请用已学过的知识编写程序,找出小甲鱼藏在下边这个长字符串中的密码,密码的埋藏点符合以下规律:
[Huawei certification] the most complete and selected question bank in hcia-datacom history (with answer analysis)
Set up lamp environment under cenos7
How to traverse objects in the vector container
基于PyQt5和Qt Designer的简易加法计算器的制作
长安链GO语言智能合约环境搭建及使用
基于keil5自动配置stm32f103标准库的官网freertos移植
2020-9-14 广告系统入门
zabbix4.4配置监控服务器指标,以及图形页乱码解决
指针函数和函数指针
Student增删gaih
Fully Automated Gross Tumor Volume Delineation From PET in Head and Neck Cancer Using Deep Learning
力扣85题最大矩形