题一:
使用大学模式(参见教材第6版第2章),用SQL写出如下查询。
找出Comp.Sci. 系开设的具有3个学分的课程名称。
select title
from course
where dept_name = 'Comp. Sci.'
and credits = 3
题二:
使用大学模式(参见教材第6版第2章),用SQL写出如下查询。
找出名叫Einstein的教师所教的所有学生的ID,保证结果中没有重复。
select distinct student.ID
from student,takes,instructor,teaches
where
student.ID=takes.ID AND
instructor.ID=teaches.ID AND
takes.course_id=teaches.course_id AND
takes.sec_id=teaches.sec_id AND
takes.semester=teaches.semester AND
takes.year=teaches.year AND
instructor.name = 'Einstein';
题三:
使用大学模式(参见教材第6版第2章),用SQL写出如下查询。
找出教师的最高工资。
select max(salary)
from instructor;
题四:
使用大学模式(参见教材第6版第2章),用SQL写出如下查询。
找出工资最高的所有教师(可能有不止一位教师具有相同的工资)。
select ID, name
from instructor
where salary = (select max(salary) from instructor);
题五:
使用大学模式(参见教材第6版第2章),用SQL写出如下查询。
找出2019年秋季开设的每个课程段的选课人数。
select course_id, sec_id, count(ID)
from section natural join takes
where semester = 'Autumn'
and year = 2019
group by course_id, sec_id;
题六:
使用大学模式(参见教材第6版第2章),用SQL写出如下查询。
从2019年秋季开设的所有课程段中,找出最多的选课人数。
select max(enrollment)
from (select count(ID) as enrollment
from section natural join takes
where semester = 'Autumn'
and year = 2019
group by course_id, sec_id);
题七:
使用大学模式(参见教材第6版第2章),用SQL写出如下查询。
找出在2019年秋季拥有最多选课人数的课程段。
with sec_enrollment as (
select course_id, sec_id, count(ID) as enrollment
from section natural join takes
where semester = 'Autumn'
and year = 2019
group by course_id, sec_id)
select course_id, sec_id
from sec_enrollment
where enrollment = (select max(enrollment) from sec_enrollment);