数据库实验《实验6》.doc

上传人:豆**** 文档编号:23865687 上传时间:2022-07-02 格式:DOC 页数:7 大小:186KB
返回 下载 相关 举报
数据库实验《实验6》.doc_第1页
第1页 / 共7页
数据库实验《实验6》.doc_第2页
第2页 / 共7页
点击查看更多>>
资源描述

《数据库实验《实验6》.doc》由会员分享,可在线阅读,更多相关《数据库实验《实验6》.doc(7页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

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

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

3、绩。14.使用游标统计每个学院教师所开设课程的选修率。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 teac

4、herselect * from studentselect * from courseinsert into course(courseno,cname,ctype,period,credit)values(c05103,高等数学,必修,64,4.0) select * from scoreinsert into score(studentno,courseno,usually,final)values(16122210009,c05103,87.00,82.00)insert into teacher(teacherno,tname,major,prof,department)values

5、(t05001,韩晋升,软件工程,教授,计算机学院)select * from classinsert into class(classno,classname,department,monitor)values(160501,计算机,计算机学院,张三)select * from teach_classinsert into teach_class(teacherno,classno,courseno)values(t05001,160501,c05103)select * from teacherselect * from courseselect * from scoreselect cl

6、assno,AVG(final) as 平均分 from student join scoreon 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.stude

7、ntno,sname,cname,final from studentjoin score on 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=0905014.select course.courseno,cn

8、ame,COUNT(studentno) fromscore join course on score.courseno=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

9、 studentno,sname,point from student wherestudentno=(select 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 s

10、corejoin student on score.studentno=student.studentnowhere 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,c

11、redit from course where not exists(select * from score 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(

12、sc2.courseno=c2.courseno)where ame=电子技术 and sc1.studentno=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

13、 final is not nullgroup by classno) tprint 所有班级期末平均成绩的最高分:+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)

14、open sc_cursorfetch next from sc_cursor into sname,cname,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

15、 cursor staticfor select department,count(*) as 选修课数 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_S

16、TATUS=0beginfetch next from curinto department,numset 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,course

17、where student.studentno=score.studentno and course.courseno=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.精品文档.实验名称

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 小学资料

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

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁