1 Star 0 Fork 0

逸扬/leetcode-hub-mysql

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
lc-1988.test 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
# $1988. 找出每所学校的最低分数要求
# https://leetcode-cn.com/problems/find-cutoff-score-for-each-school/
# SQL架构
Create table If Not Exists Schools (school_id int, capacity int);
Create table If Not Exists Exam (score int, student_count int);
Truncate table Schools;
insert into Schools (school_id, capacity) values ('11', '151');
insert into Schools (school_id, capacity) values ('5', '48');
insert into Schools (school_id, capacity) values ('9', '9');
insert into Schools (school_id, capacity) values ('10', '99');
Truncate table Exam;
insert into Exam (score, student_count) values ('975', '10');
insert into Exam (score, student_count) values ('966', '60');
insert into Exam (score, student_count) values ('844', '76');
insert into Exam (score, student_count) values ('749', '76');
insert into Exam (score, student_count) values ('744', '100');
# Write your MySQL query statement below
select
school_id,
ifnull(min(score), -1) as score
from
(
select
s.school_id,
e.score
from
Schools s
left join Exam e on s.capacity >= e.student_count
) tmp
group by
school_id;
# clean-up
drop table Schools;
drop table Exam;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gdut_yy/leetcode-hub-mysql.git
git@gitee.com:gdut_yy/leetcode-hub-mysql.git
gdut_yy
leetcode-hub-mysql
leetcode-hub-mysql
master

搜索帮助