1、 普通子查询: 1)带有IN谓词的子查询 T3:查询与“刘晨”在同一系学习的学生的学号及姓名,用嵌套查询完成 T4:查询所有选修了1号课程的学生姓名(用连接查询完成) T5:查询所有选修了1号课程的学生姓名(用嵌套查询完成) 全英文
时间: 2024-11-27 15:21:08 浏览: 59
1. **Simple Nested Queries (with IN predicate):**
a) **Query T3**: To find the student IDs and names who study with "Liu Chen" in the same department, you can use an inner query like this:
```
SELECT s.student_id, s.name
FROM students s
WHERE s.department = (
SELECT d.department
FROM departments d
WHERE d.name = '刘晨所在部门'
);
```
b) **Query T4**: To get the names of all students who have taken Course 1, you can use a join query to connect the students and courses tables:
```
SELECT sc.student_name
FROM students sc
JOIN enrollments e ON sc.student_id = e.student_id
JOIN courses c ON e.course_id = c.course_id
WHERE c.course_number = 1;
```
c) **Query T5** (using nested query): Similar to Query T4 but with a subquery for the course number:
```
SELECT sc.student_name
FROM students sc
WHERE EXISTS (
SELECT 1
FROM courses c
WHERE c.course_number = 1 AND sc.student_id = c.student_id
);
```
阅读全文