0

我正在尝试让教与教员居住在同一邮政编码中的学生的教员。

首先,我使用 intersect 找到了学生和教师共享的邮政编码。

SELECT DISTINCT FIRST_NAME,LAST_NAME,PHONE
FROM INSTRUCTOR 
 WHERE ZIP IN (
               SELECT ZIP 
               FROM STUDENT
               INTERSECT
               SELECT ZIP
               FROM INSTRUCTOR

                );

我怎样才能找到上面查询中所有学生的section_id?

SELECT SECTION_ID   
FROM STUDENT s
JOIN ENROLLMENT e ON s.STUDENT_ID = e.STUDENT_ID
JOIN SECTION w ON e.SECTION_ID = w.SECTION_ID
JOIN INSTRUCTOR z ON w.INSTRUCTOR_ID = z.INSTRUCTOR_ID;

我不知道如何获得类似于 INSTRUCTOR_ID.SECTION_ID = STUDENT_ID SECTION_ID 的内部查询,

现在我在查询中只返回所有住在那个邮政编码的老师,但我还需要检查学生正在参加那个邮政编码的教师正在教的部分......

SELECT DISTINCT FIRST_NAME,LAST_NAME,PHONE
FROM
    (
SELECT FIRST_NAME,LAST_NAME,PHONE,ZIP
FROM STUDENT 

    ) 
Derived
 WHERE ZIP IN (
               SELECT ZIP 
               FROM STUDENT
               INTERSECT
               SELECT ZIP
               FROM INSTRUCTOR

                );
4

2 回答 2

1
SELECT DISTINCT z.FIRST_NAME,z.LAST_NAME,z.PHONE
FROM STUDENT s
JOIN ENROLLMENT e ON s.STUDENT_ID = e.STUDENT_ID
JOIN SECTION w ON e.SECTION_ID = w.SECTION_ID
JOIN INSTRUCTOR z ON w.INSTRUCTOR_ID = z.INSTRUCTOR_ID AND s.ZIP = z.ZIP
于 2013-11-02T19:36:55.500 回答
1

编写一个返回教师及其学生的查询。添加教师和学生的邮政编码。添加谓词以使邮政编码必须相同。

于 2013-11-02T19:36:57.803 回答