文章目录
- 1. 题目
- 2. 解题
1. 题目
exams 表中存放着同学们的考试记录
请用 SQL 语句,找到挂科数最多的同学所对应的 student_id
https://www.lintcode.com/problem/1932
2. 解题
-- Write your SQL Query here --
-- example: SELECT * FROM XX_TABLE WHERE XXX --
select student_id from
(select sum(if(is_pass=0, 1, 0)) ct, student_id from examsgroup by student_idhaving ct > 0order by ct desclimit 1
) t
- LintCode 1933, 挂科数目最多的同学 有多位
-- Write your SQL Query here --
-- example: SELECT * FROM XX_TABLE WHERE XXX --
select student_id from
(select sum(if(is_pass=0, 1, 0)) ct, student_id from examsgroup by student_idhaving ct > 0
) t2
where ct in
(select max(ct) from (select sum(if(is_pass=0, 1, 0)) ct, student_id from examsgroup by student_idhaving ct > 0)t2
)
我的CSDN博客地址 https://michael.blog.csdn.net/
长按或扫码关注我的公众号(Michael阿明),一起加油、一起学习进步!