题目:code
有一个courses
表 ,有: student (学生) 和 class (课程)。io
请列出全部超过或等于5名学生的课。class
例如,表:test
+---------+------------+ | student | class | +---------+------------+ | A | Math | | B | English | | C | Math | | D | Biology | | E | Math | | F | Computer | | G | Math | | H | Math | | I | Math | +---------+------------+
应该输出:效率
+---------+ | class | +---------+ | Math | +---------+
Note:
学生在每一个课中不该被重复计算。select
答案1:di
select a.class from
(select count(distinct student) as num, class from courses group by class) a
where a.num >= 5时间
答案2:
select class from courses group by class having count(class) > 4vi
对比一下效率是同样的:co
[SQL] SELECT age from test_user GROUP BY age having count(age)>1;
受影响的行: 0
时间: 0.001s
[SQL]
select a.age from (select count(age) as num, age from test_user group by age) a where a.num >= 2;受影响的行: 0时间: 0.001s