我有三张表,如下所示:
Courses(
Number: integer,
DeptName: string,
CourseName: string,
Classroom: string,
Enrollment: integer)
Departments(
Name: string,
ChairmanPID: string)
PreReq(
Number: integer,
DeptName: string,
PreReqNumber: integer,
PreReqDeptName: string)
我必须找到哪些部门的课程在其他部门有先决条件?
答案 0 :(得分:1)
试试这个
Select D.Name,C.CourseName, P.DeptName
From Department D
INNER JOIN Courses C ON C.DeptName=D.DeptName
INNER JOIN PreReq P ON P.PreReqDeptName=D.DeptName AND P.DeptName <> D.DeptName
答案 1 :(得分:0)
SELECT DISTINCT p.DeptName
FROM PreReq p
WHERE p.DeptName <> p.PreReqDeptName