Leetcode 596. 超过5名学生的课

文章目录

  • 题目
  • 代码(7.20 首刷自解)

题目

Leetcode 596. 超过5名学生的课_第1张图片
Leetcode 596. 超过5名学生的课

代码(7.20 首刷自解)

group by + having

# Write your MySQL query statement below
select class from Courses group by class having count(1) >= 5;

group by + 子查询
有关键字distinct,说明同一个学生是可以重复选课的(怪不得抢课抢不到,就离谱)

# Write your MySQL query statement below
select class from (select class, count(distinct student) num from Courses group by class) t where num > 5;

你可能感兴趣的:(#,leetcode,算法,职场和发展)