这是表格,我需要弄清楚如何让哪位教师可以教授多门课程?让我们将此表称为Majors
,那么应该写些什么来找出谁可以教超过2门课程呢?
Faculty_ID Course_ID
---------------------
2130 ISM 2000
2130 ISM 3100
2143 ISM 3112
2143 ISM 3113
3487 ISM 4212
3487 ISM 4930
4756 ISM 3112
4756 ISM 3113
4756 ISM 4930
5233 ISM 3112
5233 ISM 3150
7854 ISM 2000
7896 ISM 8745
8745 ISM 6100
8759 ISM 4212
8759 ISM 6500
答案 0 :(得分:1)
使用HAVING
过滤分组结果:
select
faculty_id, count(distinct course_id)
from majors
group by faculty_id
having count(distinct course_id) > 2