有一个名为teachers
的表格,其中详细列出了包含teacher_id
,role_code
,visit_tutor
和class_code
列的教师。如果role_code
为'CT'
且visit_tutor
为null
,则教师是班级的常规教师。如果visit_tutor
不是null
,则他是班级的访问教师。
如何通过teacher_id
class_code
以及'AA'
class_code
访问班级老师,获取'BB'
教师的常规教师列表?
以下代码引发错误,因为第一个子查询返回多行:
select * from teachers where (
select teacher_id from teachers t1 where t1.role_code='CT' and t1.class_code='AA'
) in (
select teacher_id from teachers t2 where t2.visit_tutor is not null and t2.class_code='BB'
);
答案 0 :(得分:0)
那不是如何加入......
尝试:
select t1.*
from teachers t1
inner join teachers t2
on t1.teacher_id = t2.teacher_id
where t1.role_code='CT' and t1.class_code='AA'
and t2.visit_tutor is not null and t2.class_code='BB'