数据库实验4

2020-04-17 00:55

同济大学

《数据库技术及应用》

实验报告

实验报告题目:

SQL

数据查询

姓名: 杨雪纯 学号: 1257086 年级: 大二 专业:工商管理(职教师资) 指导教师: 袁科萍 日期: 2014 年 04 月 20 日

一、 实验目的

学会SQL数据查询 二、 实验内容 实验题目:

1.列出不及格记录的学生名单。

Select distinct * from student,sc where student.snum=sc.snum and score<60

2.列出选修了计算机系课程的学生姓名和年龄。

Select sname,(year(getdate())-year(birthday)) as age from student where snum in(select snum from sc

where secnum in(select secnum from sections where cnum in(select cnum from course where dept='计算机系')))

3.检索选修了数据库应用课程的学生姓名和系别。 Select sname,dept from student where snum in(select snum from sc

where secnum in(select secnum from sections where cnum in(select cnum from course where cname = '数据库应用')))

4.选修了所有课程的名单。 select * from student

where snum in( select snum from sc

group by snum having count(*)>=(select count(*) from course ))

5.检索每门课程成绩都在80分以上的学生名单。

Select distinct * from student where snum not in(select snum from sc where score<80 )

6.检索获奖学金的学生名单(每门课程在80分以上,平均成绩在90分以上)。 Select distinct * from student

where snum not in (select snum from sc

group by snum having avg(score)<90 or min(score)<80 )

7.检索选修了“大学英语”的学生名单和成绩,并按成绩从高到底排列。

Select sname ,score

from student,sc,sections,course where student.snum=sc.snum and sc.secnum=sections.secnum and sections.cnum=course.cnum and course.cname='大学英语' order by score desc

8.统计每门课程的选修人数,输出列名为课程号、人数。 select sections.cnum as 课程号,count(*) as 选课人数 from sections,sc

where sc.secnum=sections.secnum group by sections.cnum

9.查询选修了数据库应用、没有选修高等数学的学生姓名和系别。 Select student.sname,student.dept from student,sc,sections,course where student.snum=sc.snum and sc.secnum=sections.secnum and sections.cnum=course.cnum and course.cname = '数据库应用'

and student.snum not in(select snum from sc where secnum in(select secnum from sections where cnum in(select cnum from course where cname='高等数学')))

10.检索使用高等教育出版社出版的教材的课程名。

select cnum from course where textbook like'%高等教育出版社%'

11.统计所有课程的最高成绩、最低成绩和平均成绩。 Select course.cnum,cname, max(score) as 最高成绩, min(score) as 最低成绩, avg(score) as 平均成绩 from sc,sections,course

where sc.secnum in(select secnum from sections where sections.cnum = course.cnum) group by course.cnum,cname

12.统计每门课程的选课人数及不及格人数。 Select course.cnum, count(*) as 选课人数,

sum(1-score/60) as 不及格人数 from course,sections,sc

where sections.cnum=course.cnum and sc.secnum=sections.secnum group by course.cnum

13.查询土木工程系、交通工程系和城市规划系的学生学号和姓名。 Select snum,sname,dept from student

where student.dept='土木工程' or student.dept='交通工程' or student.dept='城市规划'

以下题目用集合运算符完成查询操作:

14.查询选修了数据库应用或选修了多媒体的学生学号。

Πsnum(σcname=’数据库应用’ or cname=’多媒体’(sc∞section∞course)) 15.查询计算机系且年龄不大于19岁的学生信息。

σdept=’计算机系’ and val(year(getdate())-year(birthday))<=19 (student∞sc∞section∞course))

16.查询计算机系且年龄大于

19岁的学生信息。

σdept=’计算机系’ and val(year(getdate())-year(birthday))>19 (student∞sc∞

section∞course))

三、 实验体会或收获(有感而发,没有体会也可以不写)

好难啊、难啊、啊??


数据库实验4.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:isight与 proe 和ansys集成的多学科优化案例介绍

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: