596. 超过5名学生的课 + group by + having

596. 超过5名学生的课

LeetCode_MySql_596

题目描述

方法一:使用group by + where + 子查询

# Write your MySQL query statement below
select c1.class
from (
    select class, count(distinct student) as num
    from courses
    group by class
) as c1
where 5 <= c1.num;

方法二:使用group by + having

# Write your MySQL query statement below
select class
from courses
group by class
having count(distinct student) >= 5;
posted @ 2021-03-09 20:28  Garrett_Wale  阅读(58)  评论(0编辑  收藏  举报