with target_course(id, title) as (
select course_id, title from course where dept_name = 'Comp. Sci.'
)
select distinct name from takes natural join student
where course_id in (select id from target_course);
name
----------
Bourikas
Zhang
Shankar
Williams
Levy
Brown
(6 rows)
b.找出所有没有选修在2009年春季之前开设的任何课程的学生的ID和姓名。
with student_id(ID) as (
(select ID from student)
except -- 减去所有选修2009年春季课程的学生
--找出所有选修2009年春季开设课程的学生
(select distinct ID from takes where (course_id, sec_id, semester, year)
in(
--找出2009年春季开设的所有课程
select course_id, sec_id, semester, year from section where year = 2009 and semester = 'Spring'
)))
select ID, name from student natural join student_id order by ID;