1

我正在编写一个查询来列出所有曾与 Kim (Staff_Fname) Cox (Staff_Lname) 教授任何课程或曾与 Kim Cox 在同一个房间 (Loc_id) 教授过任何课程的员工的姓名。

到目前为止,我已经写了这个(并且充满了错误):

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;

但我不确定如何包含列出在同一个房间任教的员工的部分。

数据库架构:http: //i.stack.imgur.com/dTGV5.jpg

4

1 回答 1

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" )
于 2013-05-25T00:45:39.637 回答