我正在编写一个查询,列出所有教过Kim(Staff_Fname)Cox(Staff_Lname)课程或曾在同一个房间(Loc_id)教过Kim的所有教职员工的名字和姓氏考克斯。
到目前为止,我已经写了这个(并且它充满了错误):
SELECT KimClasses.Course_Code, KimClasses.Course_Name, St2.Staff_Fname, St2.Staff_Lname
FROM
(SELECT St.Staff_id, CS.C_SE_id, C.Course_code, C.Course_name
FROM Staff St
JOIN CourseSection CS ON St.Staff_id = CS.Staff_ID
JOIN Location L ON CS.Loc_ID = L.Loc_id
JOIN Course C ON CS.Course_ID = C.Course_ID
WHERE St.Staff_Fname = "Kim"
AND St.Staff_Lname = "Cox") KimClasses
JOIN CourseSection CS2 ON KimClasses.Course_ID = CS2.Course_ID
AND NOT KimClasses.Staff_id = St2.Staff_id;
但我不确定如何将该部分列入同一房间教授的工作人员。
答案 0 :(得分:1)
这应该让你开始......
Select s.staff_fname,s.staff_lname
from staff s join course_section cs
on s.staff_if = cs.staff_id
where cs.course_id in (select distinct s1.course_id from staff s1 join course_section sc1 where s1.Staff_Fname = 'kim' and s1.Staff_Lname = "Cox" )
OR s.loc_id in (select distinct s2.loc_id from staff s2 join course_section sc2 where s2.Staff_Fname = 'kim' and s2.Staff_Lname = "Cox" )