2017-02-23 1 views
2

teacher_idrole_codevisit_tutorclass_codeの教師の詳細を持つteachersというテーブルがあります。 role_code'CT'visit_tutornullの場合、教師はクラスの正規の教師です。 visit_tutornullでない場合、彼はクラスの訪問教師です。 class_code'AA'を持つクラスの定期的な教師であり、class_code'BB'で、クラスの先生を訪問教師のteacher_idのリストを取得する方法両側の値の範囲でテーブルを自己結合する方法はありますか?

?最初のサブクエリが複数行を返すされているので

次のコードは、エラーを投げている:

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

ではありません参加する方法を...

試してみてください。

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' 
関連する問題