题目:
解答过程:
一开始输入下面这个查询语句
select teacher_id,count(subject_id) as cnt
from Teacher
group by teacher_id;
输出结果有问题:
因为1号教师在3、4系都有教2科目,所以有重复的数据。
在count()中加入distance()去重就可以了
select teacher_id,count(distinct(subject_id)) as cnt
from Teacher
group by teacher_id;