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

说明

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

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))
相关推荐
snow@li3 小时前
数据库:市场中都有哪些数据库 / 优缺点 使用情况
数据库
NoSi EFUL3 小时前
MySQL中ON DUPLICATE KEY UPDATE的介绍与使用、批量更新、存在即更新不存在则插入
android·数据库·mysql
河阿里4 小时前
SQL数据库:五大范式(NF)
数据库·sql·oracle
l1t5 小时前
DeepSeek总结的PostgreSQL 19查询提示功能
数据库·postgresql
chenxu98b6 小时前
MySQL如何执行.sql 文件:详细教学指南
数据库·mysql
刘晨鑫16 小时前
MongoDB数据库应用
数据库·mongodb
梦想的颜色7 小时前
mongoTemplate + Java 增删改查基础介绍
数据结构·数据库·mysql
小小小米粒8 小时前
redis命令集合
数据库·redis·缓存
Irene19918 小时前
SQL 中日期的特殊性总结(格式符严格要求全大写)
sql
herinspace8 小时前
管家婆实用贴-如何分离和附加数据库
开发语言·前端·javascript·数据库·语音识别