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

说明

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

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))
相关推荐
超级小忍22 分钟前
如何配置 MySQL 允许远程连接
数据库·mysql·adb
吹牛不交税35 分钟前
sqlsugar WhereIF条件的大于等于和等于查出来的坑
数据库·mysql
hshpy1 小时前
setting up Activiti BPMN Workflow Engine with Spring Boot
数据库·spring boot·后端
文牧之2 小时前
Oracle 审计参数:AUDIT_TRAIL 和 AUDIT_SYS_OPERATIONS
运维·数据库·oracle
篱笆院的狗2 小时前
如何使用 Redis 快速实现布隆过滤器?
数据库·redis·缓存
洛神灬殇3 小时前
【LLM大模型技术专题】「入门到精通系列教程」基于ai-openai-spring-boot-starter集成开发实战指南
网络·数据库·微服务·云原生·架构
小鸡脚来咯3 小时前
redis分片集群架构
数据库·redis·架构
christine-rr4 小时前
征文投稿:如何写一份实用的技术文档?——以软件配置为例
运维·前端·网络·数据库·软件构建
海尔辛4 小时前
SQL 基础入门
数据库·sql
betazhou5 小时前
有没有 MariaDB 5.5.56 对应 MySQL CONNECTION_CONTROL 插件
linux·数据库·mysql·oracle·mariadb