答案 0 :(得分:0)
对于A,您需要先连接2个表,然后group by lecturer, module
并计算每个组的行数(每行对应一个学生):
select t.lecturer, t.module, count(*) numberofstudents
from teaches t inner join studies s
on s.module = t.module
group by t.lecturer, t.module
order by t.lecturer
对于B,使用NOT EXISTS
查找所有成绩均为>= 40
的模块并计数:
select count(distinct module) numberofmodules
from studies s
where not exists (
select 1 from studies
where module = s.module and grade < 40
)