数据库系统概念机械工程出版社第二章部分习题答案

题一:
使用大学模式(参见教材第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);
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值