用凡科做的手机网站版,牡丹江到林口火车时刻表,班玛县网站建设公司,免费申请商城网站What’s more
山东大学 2020级数据库系统 实验一 山东大学 2020级数据库系统 实验二 山东大学 2020级数据库系统 实验三 山东大学 2020级数据库系统 实验四 山东大学 2020级数据库系统 实验五 山东大学 2020级数据库系统 实验六 山东大学 2020级数据库系统 实验七 山东大学 20…What’s more
山东大学 2020级数据库系统 实验一 山东大学 2020级数据库系统 实验二 山东大学 2020级数据库系统 实验三 山东大学 2020级数据库系统 实验四 山东大学 2020级数据库系统 实验五 山东大学 2020级数据库系统 实验六 山东大学 2020级数据库系统 实验七 山东大学 2020级数据库系统 实验八、九
写在前面
做数据库实验一定要静得下心来才能发现其中的错误然后进行改正。同时如果发现 SQL 语句总是报错“一定是你错了只是不知道错在哪里”
其次SQL 语句中较为复杂的点博主都进行了注释希望大家一定要看懂思路后自己写一遍而不是盲目的 CtrlCCtrlV切记切记
实验六
实验六相较于之前的实验难度稍微低一些但也需要了解视图和表的区别之后做题会更加得心应手。考察的主要是查询语句在之前的实验中想必应该非常熟悉了……
6-1 例如找出年龄小于20岁的所有学生的学号、姓名、年龄 正确执行:create view test6_00 as select sidnameage from pub.student where age20 Oracle扩展后方便写法 create or replace view test6_00 as select sidnameage from pub.student where age20 直行select count(*) from test6_00 检查是否能够5分钟内查询出全部结果如果超时说明可能有错误这种情况下严禁执行update dbtest set test6进行交卷。 找出年龄小于20岁且是物理学院的学生的学号、姓名、院系名称,按学号排序 思路 在 pub.student 中找到对应的属性值即可注意最后加上 order by sid
create view test6_01 asselect sid, name, dnamefrom pub.studentwhere age 20and sid in(select sidfrom pub.student_coursewhere dname 物理学院)order by sid6-2 查询统计2009级、软件学院每个学生的学号、姓名、总成绩列名sum_score如果有学生没有选一门课则总成绩为空值 思路 先找到满足条件的学生的 sid, name由于有学生没有选一门课但是这个学生也要计算在内因此使用 natural left outer join 来进行连接找到对应的总成绩然后连接即可
create view test6_02 asselect sid, name, sum_scorefrom (select distinct sid, namefrom pub.studentwhere class 2009and dname 软件学院) natural left outer join(select distinct sid, sum(score) sum_scorefrom pub.student_coursegroup by sid)6-3 查询2010级、计算机科学与技术学院、操作系统的学生成绩表内容有学号、姓名、成绩。 思路 根据条件进行查询即可
create view test6_03 asselect sid, name, scorefrom pub.student natural join pub.student_coursewhere class 2010and dname 计算机科学与技术学院and cid (select cid from pub.course where name 操作系统)6-4 找出选修数据库系统课程且成绩大于90的学生的学号、姓名。 思路 根据条件进行查询即可可以将两张表进行自然连接
create view test6_04 asselect sid, namefrom pub.student natural join pub.student_coursewhere cid (select cid from pub.course where name 数据库系统)and score 906-5 找出姓名叫李龙的学生的学号及其选修全部课程的课程号、课程名和成绩。 思路 名为“李龙”的同学可以不只一个哦将两张表进行自然连接后查询出满足条件的元素即可
create view test6_05 asselect sid, cid, name, scorefrom pub.student_course natural join pub.coursewhere sid in (select distinct sid from pub.student where name 李龙)6-6 找出选修了所有课程的学生的学号、姓名。 思路 使用存在性检测not exists … except(minus) … 来对所有课程和学生选课进行检验即可
create view test6_06 asselect distinct sid, namefrom pub.student Swhere not exists((select cidfrom pub.course)minus(select cidfrom pub.student_course Twhere S.sid T.sid))6-7 找出选修了所有课程并且每门课程每次考试成绩均及格的学生的学号、姓名。题6的延伸和巩固 思路 同样可以使用存在性检测先得出选修了所有课程的学生的 sid, name然后添加条件 where score 60即可 注意这里的不及格指的是只要有一次考试不及格就不计入
create view test6_07 asselect distinct sid, namefrom pub.student Swhere not exists((select cidfrom pub.course)minus(select cidfrom pub.student_course Twhere S.sid T.sid))and sid not in(select sidfrom pub.student_coursewhere score 60)6-8 找出选修了所有课程并且得到所有课程的学分即每门课程最少一次考试及格的学生的学号、姓名。题6的 延伸和巩固。 思路 首先还是使用存在性检测得出选修了所有课程的学生的 sid, name“最少一次考试及格” 的反面为 “全都不及格”因此将这些最大值不及格的学生去掉即可
create view test6_08 asselect distinct sid, namefrom pub.student Swhere not exists((select cidfrom pub.course)minus(select cidfrom pub.student_course Twhere S.sid T.sid))and sid not in(select sidfrom (select distinct sid, cid, max(score) max_scorefrom pub.student_coursegroup by sid, cid)where max_score 60)6-9 查询统计2010级、化学与化工学院的学生总学分表内容有学号、姓名、总学分sum_credit。 思路 第一步求出满足条件的学生的 sid, name第二步利用之前的方法去求出学生的总学分注意最大值 60 即计入学分哦
create view test6_09 asselect t0.sid, t0.name, t1.sum_creditfrom (select distinct sid, namefrom pub.studentwhere class 2010and dname 化学与化工学院) t0,(select distinct sid, sum(credit) sum_creditfrom (select distinct sid, cid, max(score) max_scorefrom pub.student_coursegroup by sid, cid) natural join pub.coursewhere max_score 60group by sid)t1where t0.sid t1.sid6-10 找出有间接先行课的所有课程的课程号、课程名称。 Tips所谓间接先行课某一门课程 A 的先行课 B 的先行课 C因此 C 就是 A 的间接先行课 思路 利用存在性检测 exists 即可where 条件中均为 fcid 和 cid 的比较
create view test6_10 as
select cid, name
from pub.course t0
where exists(select cidfrom pub.course t1where t0.fcid t1.cid
and exists(select cidfrom pub.course t2where t1.fcid t2.cid))再次强调一定是看懂思路之后自己实践哈~~ 有问题还请斧正