有一个courses
表 ,有: student (学生) 和 class (课程)。
请列出所有超过或等于5名学生的课。
例如,表:
+---------+------------+ | student | class | +---------+------------+ | A | Math | | B | English | | C | Math | | D | Biology | | E | Math | | F | Computer | | G | Math | | H | Math | | I | Math | +---------+------------+
应该输出:
+---------+ | class | +---------+ | Math | +---------+
Note:
学生在每个课中不应被重复计算。
第一种:
select classfrom courses group by class having count(distinct student)>=5
执行代码:
第二种:
select class from (select class,count(distinct student) as nums from courses group by class)b where nums>=5
输出:
原文地址:https://www.cnblogs.com/ConnorShip/p/10159239.html
时间: 2024-11-05 23:38:20