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

说明

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

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))
相关推荐
SelectDB5 分钟前
Agent 应用范式下,企业数据基础设施如何演进?
大数据·数据库·数据分析
杜子不疼.15 分钟前
【C++ AI 大模型接入 SDK】 - 环境搭建
开发语言·数据库·c++
qq_2837200517 分钟前
Milvus 向量数据库全链路优化实战教程
数据库·milvus
m0_7020365317 分钟前
CSS如何兼容新旧方案结合响应式容器查询
jvm·数据库·python
ClouGence23 分钟前
我们做了个疯狂的决定,把 CloudDM 全部开源了
数据库·后端·mysql
努力努力再努力wz30 分钟前
【Qt入门系列】深入理解信号与槽:从事件响应到自定义信号机制
c语言·开发语言·数据结构·数据库·c++·qt·mysql
2501_921939261 小时前
Redis
数据库·redis·缓存
星栈1 小时前
CQRS 双库架构:给事件存储单独开一个数据库,到底值不值?
数据库·全栈
YF02111 小时前
深度解构Android OkDownload断点续传
android·数据库·okhttp
测试员周周1 小时前
【Appium 系列】第04节-Page Object 模式 — BasePage 基类设计
开发语言·数据库·人工智能·python·语言模型·appium·web app