数据库实验《实验6》(共6页)

上传人:txadgkn****dgknqu... 文档编号:51130468 上传时间:2022-01-24 格式:DOC 页数:6 大小:52.50KB
收藏 版权申诉 举报 下载
数据库实验《实验6》(共6页)_第1页
第1页 / 共6页
数据库实验《实验6》(共6页)_第2页
第2页 / 共6页
数据库实验《实验6》(共6页)_第3页
第3页 / 共6页
资源描述:

《数据库实验《实验6》(共6页)》由会员分享,可在线阅读,更多相关《数据库实验《实验6》(共6页)(6页珍藏版)》请在装配图网上搜索。

1、精选优质文档-倾情为你奉上实验名称实验6实验地点8-318实验类型设计实验学时1实验日期2018-6-14 撰写注意:版面格式已设置好(不得更改),填入内容即可。一、 实验目的1. 掌握系统数据类型的特点和功能。2. 掌握创建、修改表结构的方法。3. 掌握插入、更新和删除表数据的方法。二、 实验内容1.查询所有班级的期末成绩平均分,并按照平均分降序排序。2.查询教师基本信息和教授课程信息,其中包括未分配课程的教师信息。3.查询班级中选修了“韩晋升”老师讲授的课程的学生学号、姓名、课程号和期末成绩。4.查询每门课程的课程号、课程名和选修该课程的学生人数,并按所选人数升序排序。5.查询两门及以上课

2、程的期末成绩超过80分的学生姓名及平均成绩。6.查询入学考试成绩最高的学生学号、姓名和入学成绩。7.查询同时教授c05127号和c05109号课程的教师信息。8.查询至少选修了姓名为“韩吟秋”的学生所选修课程中一门课程的学生学号和姓名。9.查询所有教授c05127号课程的教师信息。10.查询没有被任何学生选修的课程编号、课程名称和学分。11.查询“C语言”课程期末成绩比“电子技术”课程期末成绩高的所有学生的学号和姓名。12查询所有班级期末平均成绩的最高分,并将其赋值给变量,通过PRINT语句输出。13.使用游标输出学生姓名、选修课程名称和期末考试成绩。14.使用游标统计每个学院教师所开设课程的

3、选修率。15.使用游标计算学生期末成绩的等级,并更新level列。三、 实验环境1. 操作系统:Windows XP2. 开发软件:SQL Server 2008四、 提交文档提交本实验报告(电子版),文件名命名:学号 姓名实验X:XXXXXXX.doc教师将批阅后(有分数)的全体学生实验报告刻入一张光盘存档,保证光盘可读。五、 附:源代码1.select studentno,AVG(final) as 平均分 from score group by studentno order by AVG(final)2.select * from teacherselect * from studen

4、tselect * from courseinsert into course(courseno,cname,ctype,period,credit)values(c05103,高等数学,必修,64,4.0) select * from scoreinsert into score(studentno,courseno,usually,final)values(,c05103,87.00,82.00)insert into teacher(teacherno,tname,major,prof,department)values(t05001,韩晋升,软件工程,教授,计算机学院)select *

5、 from classinsert into class(classno,classname,department,monitor)values(,计算机,计算机学院,张三)select * from teach_classinsert into teach_class(teacherno,classno,courseno)values(t05001,c05103)select * from teacherselect * from courseselect * from scoreselect classno,AVG(final) as 平均分 from student join score

6、on student.studentno=score.studentno group by classnoorder by AVG(final) descselect teacher.*,cname from teacher left join teach_classon teacher.teacherno=teach_class.teachernoleft join course on teach_class.classno=course.courseno3.select student.studentno,sname,cname,final from studentjoin score o

7、n student.studentno=score.studentnojoin course on course.courseno=score.coursenowhere score.courseno in(select courseno from teach_class join teacher on teach_class.teacherno=teacher.teachernowhere tname=韩晋升)and classno=4.select course.courseno,cname,COUNT(studentno) fromscore join course on score.c

8、ourseno=course.coursenogroup by course.courseno,cnameorder by COUNT(studentno) desc5.select sname,AVG(final) from score join student on score.studentno=student.studentnowhere final=80group by student.studentno,snamehaving COUNT(courseno)=26.select studentno,sname,point from student wherestudentno=(s

9、elect top 1 studentno from student order by point)7.select teacher.teacherno,tname,major ,prof,department from teacher join teach_class on teacher.teacherno=teach_class.teachernowhere courseno=c051278.select distinct student.studentno,sname from scorejoin student on score.studentno=student.studentno

10、where courseno in(select courseno from score join student onscore.studentno=student.studentnowhere sname=韩吟秋)and sname!=韩吟秋9.select * from teacher where teacherno in(select teacherno from teach_class wherecourseno=c05127)10.select courseno,cname,credit from course where not exists(select * from scor

11、e where score.courseno=course.courseno)11.select student.studentno,sname from score sc1 join studenton (sc1.studentno=student.studentno) join course c1 on(sc1.courseno=c1.courseno)where ame=c语言 and exists(select * from score sc2 join course c2 on(sc2.courseno=c2.courseno)where ame=电子技术 and sc1.stude

12、ntno=sc2.studentnoand sc1.finalsc2.final)12.declare max numeric(6,2)select max=MAX(平均分) from (select classno as 班级号,AVG(final) as 平均分 from scorejoin student on (score.studentno=student.studentno)join course on (course.courseno=score.courseno)where final is not nullgroup by classno) tprint 所有班级期末平均成绩

13、的最高分:+cast(max as varchar(6)13.declare sname nchar(8),cname nchar(10),final numeric(6,2)declare sc_cursor cursor forselect sname,cname,finalfrom score join student on(score.studentno=student.studentno)join course on(score.courseno=course.courseno)open sc_cursorfetch next from sc_cursor into sname,cn

14、ame,finalprint 学生姓名 课程名称 期末成绩print -while FETCH_STATUS=0beginprint sname+cname+cast(final as nchar(6)fetch next from sc_cursor into sname,cname,finalendclose sc_cursordeallocate sc_cursor14.declare department nchar(30),num int,avg floatdeclare cur cursor staticfor select department,count(*) as 选修课数

15、from classwhere class.classno in(select student.classno from student group by classno)group by departmentopen curfetch curinto department,numset avg=num/(select COUNT(*) from class where department=department)print departmentprint avgwhile FETCH_STATUS=0beginfetch next from curinto department,numset

16、 avg=num/(select COUNT(*) from class where department=department)print departmentprint avgendclose curdeallocate cur15.declare sname nchar(30),cname nchar(30),final floatdeclare stu cursor staticforselect sname,final,cnamefrom student,score,coursewhere student.studentno=score.studentno and course.co

17、urseno=score.coursenoopen stufetch stuinto sname,final,cnameif final=90print N优+sname+cnameelse if final=80 and final=70 and final=60 and final70print N及+sname+cnameelse if final=90print N优+sname+cnameelse if final=80 and final=70 and final=60 and final70print N及+sname+cnameelse if final60print N差+sname+cnameendclose studeallocate stu专心-专注-专业

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!