版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、实验三 数据查询实验实验目的通过对实验二中建立的学生数据库关系表和视图的各种查询的操作,加深对SQL查询语言的了解,掌握相关查询语句的语法和使用方法。实验步骤1、在简单查询实验中,在sql语句完成以下查询操作:1查询“数据库原理课程的学分; select credit from course where course_name='数据库原理'2查询选修了课程编号为“C01的学生的学号和成绩,并将成绩按降序输出;select student_id,scorefrom scwhere course_id='C01'order by score desc一共25条查询
2、结果(3) 查询学号为“31401的学生选修的课程编号和成绩;select course_id,scorefrom sc where student_id=31401一共3条查询结果4查询选修了课程编号为“C01且成绩高于85分的学生的学号和成绩。select student_id ,scorefrom sc where course_id='C01' and score >85一共5条查询结果2、在多表连接的查询实验中,在SQLSERVER提供的交互式语言环境下用Transact SQL语句完成以下查询操作:1查询选修了课程编号为“C01且成绩高于85分的学生的学号、姓
3、名和成绩;select sc.student_id ,student_name,scorefrom sc,student where sc.course_id ='C01' and sc.student_id =student.student_id and sc.score >85一共5条查询结果(2) 查询所有学生的学号、姓名、选修的课程名称和成绩;select sc.student_id,student_name,course_name,scorefrom sc,student,course where sc.student_id =student.student_i
4、d and sc.course_id =course.course_id 一共142条查询结果3、在复杂查询实验中,用 SQL语句完成以下查询操作:1查询至少选修了三门课程的学生的学号和姓名;select sc.student_id,student.student_name,COUNT(sc.course_id )from sc,student where sc.student_id =student.student_id group by sc.student_id,student_name having COUNT(sc.course_id )>=3一共39条查询结果(2) 查询所有
5、学生的学号和他选修课程的最高成绩,要求他的选修课程中没有成绩为空的。select sc .student_id,student_name,max(score ) as max_scorefrom sc,studentwhere sc.student_id in(select sc .student_idfrom sc,student where sc.student_id =student.student_id)except(select sc .student_idfrom sc,student where sc.student_id =student.student_id and scor
6、e is NULL)and sc.student_id =student.student_idgroup by sc .student_id,student_name一共52条查询结果,成绩为NULL的30401和30402号同学有成绩为空,不在查询结果中4、 在嵌套查询实验中,在SQLServer提供的交互式语言环境下用iSQL语句完成以下查询操作,要求写嵌套查询语句:(1) 查询选修了数据库原理的学生的学号和姓名;select student_id ,student_name from studentwhere student_id in (select student_id from s
7、c,course where sc.course_id =course.course_id and course_name='数据库原理' )一共23条查询结果(2) 查询没有选修数据库原理的学生的学号和姓名;select student_id ,student_name from studentwhere student_id not in (select student_id from sc,course where sc.course_id =course.course_id and course_name='数据库原理' )一共31条查询结果3查询至少选
8、修了学号为“31401的学生所选修的所有课程的学生的学号和姓名。select student_id ,student_name from student as Swhere not exists( (select course_id from sc where sc.student_id =31401) except (select course_id from sc as T ,student as R where T.student_id =R.student_id and S.student_name=R.student_name )一共20条查询结果视图查询:对实验二建立的视图进行相关
9、的查询操作,如:(1) 查询选修了课程编号为“C01的学生的学号和成绩;select student_id,student_namefrom studentviewwhere course_id='C01'一共25条查询结果(2) 查询所有学生的学号、姓名、选修的课程名称和成绩;select student_id,student_name,course_id,scorefrom studentview一共142条查询结果3查询选修了数据库原理的学生的学号和姓名。select student_id,student_name,course_namefrom studentvieww
10、here course_name='数据库原理'一共23条查询结果实验总结:本次实验中遇到的一些问题:1、 首先遇到的问题是Sybase和SQLServer都不能用了,不管怎么重启都不行,查了一些资料是因为IP地址被修改了所以连接不上,在对Sybase做了一些设置以后还是用不了,但是SQLServer可以用localhost连接效劳器,所以本次实验只好用SQLServer2、 在查询所有学生的学号和他选修课程的最高成绩,要求他的选修课程中没有成绩为空的这个查询操作的时候出现了问题,我开始的时候想到把所有同学除去成绩有空同学就可以得到正确的查询结果,但是实际上这样做的结果是不正确的,我把excep
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 石料厂施工安全管理制度培训课件
- 2026安徽工会面试题库及答案
- 2026阿里经典面试题目及最佳答案
- 第五单元(B卷能力提升卷)-《思政 心理健康与职业生涯》(高教版) 单元过关卷答案
- 山东省德州市乐陵市2024-2025学年七年级上学期语文期末试卷(含答案)
- 第四单元(A卷基础巩固卷)-《思政 心理健康与职业生涯》(高教版) 单元过关卷
- 2026年护师类之儿科护理主管护师押题练习试题(含答案)
- 护理AI在护理质量改进中的应用
- 2026年屋顶搭铁工程承包合同二篇
- 2026一级造价工程师《计价》计算公式考点速记
- 探究古代闽剧人物造型的转变
- 2023年中级消防设施操作员(监控方向)理论知识考试题库(浓缩500题)
- GB/T 1112-2012键槽铣刀
- 2020年事业单位考试必考的180个公共基础知识要点精髓整理总结
- 低温固定储罐培训课件
- 复旦眼科学课件03眼底病
- 力克使用说明书
- 三防漆外观检验标准
- 海南大学应用科技学院风景园林专业自评材料
- 斗轮堆取料机培训教材
- 5免除知情同意书申请表-四川大学华西医院
评论
0/150
提交评论