考虑以下三个表来存储学生在不同课程中的入学率。
null
Student(EnrollNo, Name) Course(CourseID, Name) EnrollMents(EnrollNo, CourseID)
下面的查询做什么?
SELECT S.Name FROM Student S, Course C, Enrollments E WHERE S.EnrollNo = E.EnrollNo AND C.Name = "DBMS" AND E.CourseID = C.CourseID AND S.EnrollNo IN (SELECT S2.EnrollNo FROM Student S2, Course C2, Enrollments E2 WHERE S2.EnrollNo = E2.EnrollNo AND E2.CourseID = C2.CourseID C2.Name = "OS")
(A) 所有注册“DBMS”或“OS”课程的学生的姓名 (B) 所有注册“DBMS”和“OS”的学生的姓名 (C) 所有注册“DBMS”或“OS”或两者的学生的姓名。 (D) 非上述因素 答复: (B) 说明:
背景阅读:以上查询是一个 嵌套查询 i、 e.查询中的查询。首先解决内部查询,然后根据内部查询的结果解决外部查询。
- 其中IN返回与列表或子查询中的值匹配的值。
- 其中IN是多个或多个条件的简写。
Here, firstly the inner query is solved. It returns all the Enrollment Numbers (SELECT S2.EnrollNo) of students where the students’ enrollment number matches with the enrollment number of the courses (WHERE S2.EnrollNo = E2.EnrollNo) which have the course IDs whose Course Name is “OS” (E2.CourseID = C2.CourseID and C2.Name = “OS”).
因此,所有注册ID都会被过滤掉,以供注册“OS”课程的学生使用。
The outer query works similarly and filters out all the all tuples where the Students Enrollment Number matches with the Enrollment Number where the course ID’s are for the course names “DBMS” (S.EnrollNo = E.EnrollNo AND C.Name =”DBMS” AND E.CourseID = C.CourseId) and additionally matches with the ones that are returned by the inner query i.e. Enrollment Number of students who are enrolled for the course “OS”.
因此,上述查询将返回所有同时注册“DBMS”和“OS”课程的学生的姓名(选择S.Name)。
因此,选择(B)。
这一解释是由 安倍晋香。 这个问题的小测验
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END