2014-02-06 57 views
0

我有三個表,如下圖所示:選擇部門名稱預查詢requiste

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

如何其更多鈔票的SQL Server和MySQL?你真的在使用什麼? – Melon

回答

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 
0
SELECT DISTINCT p.DeptName 
FROM PreReq p 
WHERE p.DeptName <> p.PreReqDeptName 
相關問題