


全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
17.6 T-SQL高级查询一、目的1.掌握SELECT语句在单表查询中的应用(分组、统计函数等)2.掌握基于多表的连接查询3.掌握嵌套子查询二、内容1. 上机验证第章所有实例2上机完成第章有关练习3利用SQL Server Management Studio把JWGL数据库还原,然后进行下面的操作。17.6 T-SQL高级查询一、目的1.掌握SELECT语句在单表查询中的应用(分组、统计函数等)2.掌握基于多表的连接查询3.掌握嵌套子查询二、内容1. 上机验证第章所有实例2上机完成第章有关练习3利用SQL Server Management Studio把JWGL数据库还原,然后进行下面的操作。1)查询数据库中班的平均成绩。select avg(grade) from result where student_id in(select student_id from student where class_id in (select class_id from class where class_id =200302)2)查询程序设计这门课的最高分、最底分及其之间的分差。select max(grade),min(grade), max(grade)-min(grade) from result where course_id in(select course_id from course where name=程序设计)3)查询总分大于分的学生的学号及总成绩。select student_id,sum(grade) from result group by student_id having sum(grade)3504)统计学生来自多少个城市。select count(distinct left(home_addr,3) from student5)查询每个教师的教师号及其任课门数。select teacher_id, count(distinct course_id) from teaching group by teacher_id6)查询选修三门以上课程的学生学号和选课门数。 Select student_id,count(distinct course_id) from RESULT group by STUDENT_id7)统计男、女学生各自的总人数和平均年龄。Select sex,count(student_id),AVG(year(getdate()-(year(birthday)From student group by sex8)查询刘老师所讲授的课程名称。Select from course where course_id in(Select course_id from teaching where teacher_id in(Select teacher_id from teacher where like 刘%)9)查询比杨勇年龄大的学生基本信息。Select * from student where birthday(select birthday from student where name=杨勇)10)查询所有选课学生的学号、姓名、选课名称及成绩。Select s.student_id,,,r.grade from student s,course c,result r where s.student_id=r. student_id andc.course_id=r. course_id11)查询成绩有不及格的学生的学号和姓名。Select s.student_id,,,r.grade from student s,course c,result r where s.student_id=r. student_id andc.course_id=r. course_idand r.grade70 and =数据库14)用COMPUTE BY子句按学号汇总出result表中每个学生的学号及各门课的平均成绩和总成绩。Select student_id,course_id, grade from result order BY student_idCompute avg(grade),sum(grade)BY student_id15)查询程序设计课程分数最高的学生的基本信息。Select * from student where student_id=( Select student_id from result Where grade= (Select max(grade) from result where course_id=(select course_id from course where name=程序设计)16) 查找不同课程但成绩相同的学生数、课程数和成绩。select count(distinct student_id) 学生数,count(distinct course_id) 课程数,grade 成绩from result group by grade17)查询姓张的学生的学号及其所选修的课程名称和所修成绩。Select ,s.student_id,,r.grade from student s,course c,result r where s.student_id=r. student_id andc.course_id=r. course_idand like 张%18)统计选修了微机原理的学生名单。Select name from student where student_id in (select student_id from result where course_id=(select course_id from course where name=微机原理)19) 查询没有成绩的学生姓名和对应的课程名称。Select , from student s,course c,result r where r.grade is null and c.course_id=r. course_id and s.student_id=r.student_id20) 查询其他系中比信息系任一教师工资高的教师的姓名和工资。Select name,salary from teacher where salary(select max(salary) from teacher where department_id=(select department_id from department where department=信息系)21)查询不讲授课程号为C01的教师姓名。Select name from teacher where teacher_id in(select distinct teacher_id from teaching where course_id!=C01)22) 把所有教师的工资提高到平均工资的.2倍。Declare a as moneySelect a=avg(salary) from teacherUpdate teacher Set sa
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 管理学组织与团队核心考点试卷训练
- 航空器维修技术规范与标准
- 宜昌国企考试试题及答案
- 沂水编制考试试题及答案
- 医院收费考试试题及答案
- 六一公司工会活动方案
- 六一吃大餐活动方案
- 六一城堡活动方案
- 六一居家趣味活动方案
- 六一庙会活动方案
- 历代中医名人
- 垃圾渗滤液处理站运维及渗滤液处理投标方案(技术方案)
- 国家开放大学本科《商务英语4》一平台机考真题及答案(第二套)
- JG-T 568-2019 高性能混凝土用骨料
- 变电站一键顺控改造技术规范(试行)
- 光储充一体化充电站设计方案
- JTT 854-2013 公路桥梁球型支座规格系列
- 《公路桥涵施工技术规范》JTGT3650-2020
- 2024年湖北省中考英语试题(附答案)
- 2023-2024学年广东省深圳市龙岗区六年级下学期模拟数学试题含解析
- 期末考试试卷(试题)-2023-2024学年三年级下册数学北师大版
评论
0/150
提交评论