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

说明

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

# 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))

相关推荐

  1. 数据库作业官方答案

    2024-04-21 11:52:01       40 阅读
  2. 作业

    2024-04-21 11:52:01       36 阅读
  3. 数据库作业

    2024-04-21 11:52:01       37 阅读
  4. 数据库作业

    2024-04-21 11:52:01       44 阅读
  5. 数据库作业

    2024-04-21 11:52:01       38 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-21 11:52:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-21 11:52:01       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-21 11:52:01       87 阅读
  4. Python语言-面向对象

    2024-04-21 11:52:01       96 阅读

热门阅读

  1. 聊聊linux的文件缓存

    2024-04-21 11:52:01       39 阅读
  2. 从表中生成SQL*Loader insert into 语句

    2024-04-21 11:52:01       31 阅读
  3. 框架中的单例模式

    2024-04-21 11:52:01       34 阅读
  4. STM32

    STM32

    2024-04-21 11:52:01      31 阅读
  5. STM32几种库的比较,HAL、标准库、LL库!

    2024-04-21 11:52:01       33 阅读
  6. STM32

    STM32

    2024-04-21 11:52:01      29 阅读
  7. stylus入门使用方法

    2024-04-21 11:52:01       37 阅读
  8. 分布式限流——Redis + Lua实现滑动窗口算法

    2024-04-21 11:52:01       41 阅读