版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、实验一数据库查询课程名称:实验名称数据库原理实验数据库查询实验类型:学时验证型4 学时实验目的:使学生掌握 SQL Server Query Analyzer 的使用方法,加深对 SQL 和 T-SQL 语言的查询语句的理解。熟练掌握表的基本查询,连接查询和嵌套查询,以及掌握数据排序和数据分组的操作方法。实验原理:SELECT ALL|DISTINCT < 目标列表达式> , <目标列表达式FROM<表名或视图名> , <表名或视图名>WHERE < 条件表达式 >GROUP BY < 列名 1> HAVING <条件表达
2、式 >order by <列名 2> ASC|DESC;>实验方法 :将查询需求用T-SQL 语言表示;在SQL Server Query Analyzer的输入区中输入 T-SQL 查询语句;设置Query Analyzer的结果区为Standard Execute(标准执行)或 Execute to Grid (网格执行)方式;发布执行命令,并在结果区中查看查询结果;如果结果不正确,要进行修改,直到正确为止。实验内容:1.分别用带DISTINCT 和不带 DISTINCT 关键字的SELELCT在 student中进行查询 .带 distinct:Selectcla
3、ss_idfromstudent不带 distinct:selectdistinctclass_idfromstudent2.将 teacher表中各教师的姓名、教工号及工资按按 95发放后的列名改为预发工资95 发放的信息,并将工资selectteacher_id,teacher_name,salary *0.95as 预发工资fromteacher3.查询course表中所有学分大于2 并且成绩不及格的学生的信息.selectdistinctstudent.*fromstudent,course,scwherestudent.student_id=sc .student_idandsc .
4、course_id= course .course_idandcourse .credit> 2andsc .grade<604.查询学分在4 8之间的学生信息(. 用between.and和复合条件分别实现)select distinct student .* from student ,course ,sc where student .student_id and sc .course_id and course .credit=sc . student_id=course .course_idbetween4 and85. 从 student_course 表中查询出学生为
5、 “ g9940201 ”,“ g9940202 ”的课程号、学生号以及学分,并按学分降序排列(用in 实现)select*fromsc ,coursewherestudent_idin( 'g9940201','g9940202')andcourse .course_id= sc .course_idorderby course.creditdesc6.从 teacher表中分别检索出姓王的教师的资料,或者姓名的第2 个字是远或辉的教师的资料select*fromteacherwhereteacher_namelike '王 %'or teac
6、her_namelike '_ 远 %'or teacher_namelike '_辉 %'7. 查询每个学生及其选修课情况selectstudent_name,course_namefromstudent, sc ,coursewheresc .student_id=student.student_idandsc .course_id=course .course_id8. 以 student 表为主体列出每个学生的基本情况及其选课情况,如果学生没有选课,只输出其基本情况selectstudent.*,course.*fromstudentjoin scons
7、tudent.student_id= sc .student_idleftjoin courseoncourse. course_id=sc .course_id9.查询选修dep04_s001号课程且成绩在80 分以上的学生信息。 (分别用连接,in 和 exists 实现)连接:selectstudent.*fromsc ,studentwheresc .student_id= student.student_idandsc .course_id= 'dep04_s001'andsc .grade> 80In :select*fromstudentwherestude
8、nt_idin(selectstudent_idfromscwherecourse_id='dep04_s001'andgrade> 80)exists :select*fromstudentwhereexists(selectstudent_idfromscwherestudent.student_id=sc .student_idandcourse_id= 'dep04_s001'andgrade> 80)10. 查询所有上计算机基础课程的学生的学号、 选修课程号以及分数 (分别用连接, in 和 exists 实现)连接:selectsc .*
9、fromsc ,coursewherecourse .course_name= '计算机基础'andcourse .course_id= sc .course_idIn :selectstudent_id,course_id,gradefromscwherecourse_idin(selectcourse_idfromcoursewherecourse_name= '计算机基础')exists :selectstudent_id,course_id,gradefrom sc whereexists(select*fromcoursewherecourse_id=
10、 sc .course_idandcourse_name= '计算机基础')11.查询选修了课程名为“数据库基础”的学生学号和姓名(分别用连接,exists 实现)in和连接:selectstudent.student_id,student.student_namefromsc ,student,coursewherecourse .course_name= '数据库开发技术andsc .student_id= student.student_idandcourse .course_id= sc .course_id'In :selectstudent_id,s
11、tudent_namefromstudentwherestudent_idin(selectstudent_idfrom scwherecourse_id=(selectcourse_idfromcoursewherecourse_name= '数据库开发技术' ) )exists :selectstudent_id,student_namefrom studentwhereexists(select*fromscwheresc .student_id= student.student_idandsc .course_id=(selectcourse_idfromcoursew
12、herecourse_name=' 数据库开发技术' )12. 查询所有计算机系学生的学号、 选修课程号以及分数 (分别用连接, in 和 exists 实现)连接:selectsc .*fromsc ,department,studentwheredepartment.department_name= '计算机科学 'anddepartment.department_id= student.department_idandsc .student_id= student.student_idIn :select *fromscwherestudent_idin(
13、selectstudent_idfrom studentwheredepartment_id=(selectdepartment_idfromdepartmentwheredepartment_name= '计算机科学')exists :select *from scwhereexists (select * from student where student . student_id and student .department_id= sc .student_id=(selectdepartment_idfromdepartmentwheredepartment_nam
14、e= '计算机科 ')13 查询每个dep_04系学生的总成绩、平均成绩,仅显示平均成绩及格的学生的记录。selectstudent.student_name,sum (grade) as 总成绩 ,avg (gradefrom sc , student,departmentwheresc .student_id= student.student_idandstudent.department_id=department.Department_idanddepartment.department_id= 'dep_04'groupby student.stude
15、nt_id,student_namehavingavg (grade)> 60) as平均成绩14查询“数据库开发技术”的平均成绩selectavg (grade) as数据库开发平均成绩from scwherecourse_idin(selectcourse_idfromcoursewherecourse_name= '数据库开发技术')15按职称查询教师的平均工资,并按总工资降序排列selectprofession,avg ( salary ) as 平均工资 , sum (salary ) as总工资from teachergroupby professionord
16、erby sum (salary ) desc附录 1:教务管理数据库jwgl 结构student 表结构列名称数据类型长度允许空值说明Student_idChar8否学生学号Student_nameVarchar8否学生姓名SexBit1否性别AgeInt4否年龄Class_idChar6否班级号Department_idChar6否系编号Addressvarchar50否家庭住址Course 表字段名称数据类型长度允许空说明Course_idChar10否课程号Course_nameVarchar20否课程名称Book_idChar15否书标识SC 表字段名称数据类型长度允许空说明Cour
17、se_idChar10否课程号Student_idVarchar8否学生号gradeTinyint否成绩creditTinyint否学分Teacher 表字段名称数据类型长度允许空说明Teacher_idChar9否教师编号Teacher_namenvarchar8否教师姓名Department_idChar6否所在系号ProfessionNvarchar16职称SexBit否性别phoneNvarchar15是电话adressNchar40是住址SalaryNumeric7.2是工资BirthSmalldatetime否出生日期PostalcodeNumeric6,0是邮编Book 表字段名称数据类型长度允许空说明Book_idChar13否书号Book_nameVarchar
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 节假日零售连锁店促销活动方案
- 通信设备行业研发创新与技术升级方案
- 网络游戏设计与开发完全手册
- 关于更新企业形象识别系统的商洽函8篇范本
- 质量检测人员产品检测流程手册
- 健身房会员健康管理计划制定方案
- 2026年运输企业应急救援队伍建设与装备使用培训
- 2026年科技创新项目申报书范本
- 2026年销售部门工作总结及计划
- 2026年玻璃幕墙安装施工安全协议
- 领导带班及24小时值班制度
- 食品安全自查、从业人员健康管理、进货查验记录、食品安全事故处置保证食品安全的规章制度
- 电影鉴赏评论知到智慧树章节测试课后答案2024年秋山东艺术学院
- 2026年1月1日起施行新增值税法全文课件
- 【可见光室内定位系统的设计与实现(论文)8000字】
- 人教版五年级数学下册测试题(全套)-五年下册人教数学测试题
- 2023年深圳市公安局招聘警务辅助人员考试真题
- T-CPA 006-2024 造纸用湿强剂 聚酰胺环氧氯丙烷PAE
- (完整版)全等三角形经典模型总结
- JBT 5300-2024 工业用阀门材料 选用指南(正式版)
- 新能源汽车消防安全培训
评论
0/150
提交评论