一直試圖解決此查詢幾個小時。SQL:在兩門課程上顯示具有相同教師的學生
我有以下表格:
Student
(StudenNumber* INT, ID TEXT, Fname TEXT, Lname TEXT, Institute TEXT, EnrollYear INT)
Teacher
(ID* TEXT, Fname TEXT, Lname TEXT, Insitutue TEXT)
Course
(ID* TEXT, Name TEXT, Type TEXT, Weeks INT, Period INT, Year INT, Subject TEXT, Teacher TEXT)
Institute
(Name* TEXT, Faculty TEXT)
Subject
(Name* TEXT, Examination TEXT, Insitute TEXT)
Grade
(Course* TEXT,Student* INT, Grade INT)
Examination
(ID* TEXT, ExaminationName* TEXT)
,我試圖讓顯示所有有過同樣的老師在兩個療程(刪除重複)的學生。
我的查詢沒有返回正是我要找:
SELECT DISTINCT E.Fname, E.Lname
FROM STUDENT E
WHERE EXISTS (SELECT COUNT(A.TEACHER)
FROM COURSE A, COURSE B
WHERE A.Teacher = B.Teacher
GROUP BY Teacher
having COUNT(*) = 2);
您的子查詢需要引用E.(不好的表別名選擇...) – jarlh