赞
踩
山东大学 2020级数据库系统 实验一
山东大学 2020级数据库系统 实验二
山东大学 2020级数据库系统 实验三
山东大学 2020级数据库系统 实验四
山东大学 2020级数据库系统 实验五
山东大学 2020级数据库系统 实验六
山东大学 2020级数据库系统 实验七
山东大学 2020级数据库系统 实验八、九
做数据库实验一定要静得下心来,才能发现其中的错误然后进行改正。同时,如果发现 SQL 语句总是报错,“一定是你错了,只是不知道错在哪里!”
其次,SQL 语句中较为复杂的点博主都进行了注释,希望大家一定要看懂思路后自己写一遍,而不是盲目的 Ctrl+C,Ctrl+V,切记切记!!
实验六相较于之前的实验难度稍微低一些,但也需要了解视图和表的区别之后,做题会更加得心应手。考察的主要是查询语句,在之前的实验中想必应该非常熟悉了……
create view test6_01 as
select sid, name, dname
from pub.student
where age < 20
and sid in
(select sid
from pub.student_course
where dname = '物理学院')
order by sid
create view test6_02 as
select sid, name, sum_score
from
(select distinct sid, name
from pub.student
where class = '2009'
and dname = '软件学院')
natural left outer join
(select distinct sid, sum(score) sum_score
from pub.student_course
group by sid)
create view test6_03 as
select sid, name, score
from pub.student natural join pub.student_course
where class = '2010'
and dname = '计算机科学与技术学院'
and cid = (select cid from pub.course where name = '操作系统')
create view test6_04 as
select sid, name
from pub.student natural join pub.student_course
where cid = (select cid from pub.course where name = '数据库系统')
and score > 90
create view test6_05 as
select sid, cid, name, score
from pub.student_course natural join pub.course
where sid in (select distinct sid from pub.student where name = '李龙')
create view test6_06 as
select distinct sid, name
from pub.student S
where not exists
((select cid
from pub.course)
minus
(select cid
from pub.student_course T
where S.sid = T.sid))
6-7 找出选修了所有课程并且每门课程每次考试成绩均及格的学生的学号、姓名。(题6的延伸和巩固)
思路:
注意:这里的不及格指的是只要有一次考试不及格就不计入!!!
create view test6_07 as
select distinct sid, name
from pub.student S
where not exists
((select cid
from pub.course)
minus
(select cid
from pub.student_course T
where S.sid = T.sid))
and sid not in
(select sid
from pub.student_course
where score < 60)
create view test6_08 as select distinct sid, name from pub.student S where not exists ((select cid from pub.course) minus (select cid from pub.student_course T where S.sid = T.sid)) and sid not in (select sid from (select distinct sid, cid, max(score) max_score from pub.student_course group by sid, cid) where max_score < 60)
create view test6_09 as
select t0.sid, t0.name, t1.sum_credit
from
(select distinct sid, name
from pub.student
where class = '2010'
and dname = '化学与化工学院') t0,
(select distinct sid, sum(credit) sum_credit
from (select distinct sid, cid, max(score) max_score
from pub.student_course
group by sid, cid) natural join pub.course
where max_score >= 60
group by sid)t1
where t0.sid = t1.sid
create view test6_10 as
select cid, name
from pub.course t0
where exists
(select cid
from pub.course t1
where t0.fcid = t1.cid
and exists
(select cid
from pub.course t2
where t1.fcid = t2.cid))
再次强调:一定是看懂思路之后自己实践哈~~
有问题还请斧正!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。