数据库第五次作业官方答案

说明

之前的互评结束之后就无法查看答案,所以想着互评期间把答案保存下来,方便之后进行复习

sql 复制代码
# 1.1
select ID, name,sec_id
from instructor natural left outer join teaches;

# 1.2
select ID,name, count(sec_id) as Numberofsetions
from instructor natural left outer join teaches
group by ID,name

# 1.3
select  ID,name,
(select count(*) a from teaches T where T.id = I.id) Numberofsetions
from instructor I;

# 2.1
select course_id, sec_id, ID,decode(name, null, '-', name) as name
from (section natural left outer join teaches)
natural left outer join instructor
where semester='Spring' and year= 2020;

# 2.2
select dept_name, count(ID)
from department natural left outer join instructor
group by dept_name;

# 2.3
select dept_name, 
(select count(*) a from instructor i where i.dept_name=d.dept_name ) Numberofinstructors
from department d;

# 3.1
(select sum(credits * points)
from (takes natural join course) natural join grade_points
where ID = '12345')
union
(select 0
from student
where ID = '12345' and
not exists ( select * from takes where takes.ID = '12345'))

# 3.2
(select sum(credits * points)/sum(credits) as GPA
from (takes natural join course) natural join grade_points
where ID = '12345')
union
(select null as GPA
from student
where ID = '12345' and
not exists ( select * from takes where takes.ID = '12345'))

# 3.3
(select ID, sum(credits * points)/sum(credits) as GPA
from (takes natural join course) natural join grade_points
group by ID)
union
(select ID, null as GPA
from student
where not exists ( select * from takes where takes.ID = student.ID))
相关推荐
IT邦德2 分钟前
Oracle向量数据库实战
数据库·oracle
2401_8735449215 分钟前
使用Python处理计算机图形学(PIL/Pillow)
jvm·数据库·python
路由侠内网穿透17 分钟前
本地部署开源工作空间工具 AFFiNE 并实现外部访问
运维·服务器·数据库·物联网·开源
njidf20 分钟前
自动化机器学习(AutoML)库TPOT使用指南
jvm·数据库·python
F1FJJ25 分钟前
什么是 Shield CLI?视频讲解:一条命令,可浏览器远程访问一切内部服务(RDP/VNC/SSH/数据库等)
运维·网络·数据库·网络协议·ssh
星辰_mya1 小时前
InnoDB的“身体结构”:页、Buffer Pool与Redo Log的底层奥秘
数据库·mysql·spring·面试·系统架构
F1FJJ1 小时前
Shield CLI 命令全解析:15 个命令覆盖所有远程访问场景
网络·数据库·网络协议·容器·开源软件
IMPYLH1 小时前
Linux 的 dircolors 命令
linux·运维·服务器·数据库
2301_822782822 小时前
自动化与脚本
jvm·数据库·python
qq_148115372 小时前
为你的Python脚本添加图形界面(GUI)
jvm·数据库·python