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

596. 超过5名学生的课

LeetCode_MySql_596

题目描述

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

方法一:使用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;
上一篇:Where和having的区别


下一篇:count(*)和count(具体的某个字段),他们有什么区别? group by 和 having