



免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
试验七 Sql 查询语句目的: 掌握 Select 查询语句。一 单表1查询年龄在19至21岁之间的女生的学号,姓名,年龄,按年龄从大到小排列。select sno,sname,sage from studentwhere sage between 19 and 21 and ssex=女 order by sage desc2查询姓名中第戎2个字为“明”字的学生学号、性别。select sname ,ssex from student where sname like _明%3查询 1001课程没有成绩的学生学号、课程号select sno,cno from sc where grade is null and cno=10014查询JSJ 、SX、WL 系的学生学号,姓名,结果按系及学号排列select sno,sname from student where sdept in (JSJ,SX,WL)order by sdept,sno5按10分制查询学生的sno,cno,10分制成绩 (1-10分 为1 ,11-20分为2 ,30-39分为3,。90-100为10)select sno , cno , grade/10.0+1 as level from sc6查询 student 表中的学生共分布在那几个系中。(distinct)select distinct sdept from student7查询0001号学生1001,1002课程的成绩。 Select cno from sc where sno=0001 and (cno=1001 or cno=1002)二 统计1查询姓名中有“明”字的学生人数。select count(*) from student where sname like %明%2计算JSJ系的平均年龄及最大年龄。 Select avg(sage) , max(sage) from student Where sdept=JSJ3计算每一门课的总分、平均分,最高分、最低分,按平均分由高到低排列 select cno,sum(grade),avg(grade),max(grade),min(grade) from sc group by cno order by avg(grade) desc4 计算 1001,1002 课程的平均分。Select cno , avg(grade) from sc where cno in (1001,1002)Group by cno5 查询平均分大于80分的学生学号及平均分select sc.sno , avg(grade) from scgroup by sc.snohaving avg(grade)806 统计选修课程超过 2 门的学生学号 select sno from sc group by sno having count(*)27 统计有10位成绩大于85分以上的课程号。Select cno from scwhere grade85group by cno having count(*) =108 统计平均分不及格的学生学号select sno from sc group by sno having avg(grade)609 统计有大于两门课不及格的学生学号select sno from sc where grade2三 连接1查询 JSJ 系的学生选修的课程号 select cno from student,sc where student.sno=sc.sno and sdept=JSJ2查询选修1002 课程的学生的学生姓名 (不用嵌套及嵌套2种方法)a: select sname from student,sc where student.sno = sc.sno and cno=1002b: select sname from student where sno in (select sno from sc where cno=1002)3查询数据库原理不及格的学生学号及成绩select sno,grade from sc ,coursewhere o=o and cname=数据库原理4查询选修“数据库原理”课且成绩 80 以上的学生姓名(不用嵌套及嵌套2种方法)a: select sname from student , sc , course where student.sno=sc.sno and o = o andgrade80 and cname=数据库原理b: select sname from student where sno in ( select sno from sc where grade80 and cno in ( select cno from course where cname=数据库原理) )5查询平均分不及格的学生的学号,姓名,平均分。select sno, max(sname) , avg(grade) as avggrade from sc , studentwhere student.sno=sc.snogroup by student.snohaving avg(grade) 75)B: Select max(sname ) from sc,student where student.sno=sc.sno and Ssex=女 Group by student.sno having avg(grade)757查询男学生学号、姓名、课程号、成绩。(一门课程也没有选修的男学生也要列出,不能遗漏)select student.sno,sname,cno,grade from student left join sc ON student.sno=sc.sno and ssex=男四 嵌套、相关及其他1 查询平均分不及格的学生人数select count(*) from student where sno in (select sno from sc group by sno having avg(grade)=all ( select avg(grade) from sc group by sno )*4 查询没有选修1001,1002课程的学生姓名。Select sname from student where not exists ( Select * from course where cno in (1001,1002) and Not exists ( select * from sc where sno=student.sno and cno=o ) )5 查询1002课程第一名的学生学号(2种方法)a: select top 1 sno from sc cno=1002 order by grade descb: select sno from sc where cno=1002 andgrade =all (select grade from sc where cno=1002)6 查询平均分前三名的学生学号select top 3 sno from sc group by sno order by avg(grade) desc7 查询 JSJ 系的学生与年龄不大于19岁的学生的差集a: select * from student where sdept=JSJ and sage19b: select * from student where sdept=JSJ except select * from student where sage90unionselect sno,sname from student where sno in ( select sno from sc group by sno
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 21759-2025化学品慢性毒性试验方法
- 2025年合肥庐江县绣溪城市服务有限公司招聘2人考前自测高频考点模拟试题及答案详解参考
- 2025广东佛山市顺德区公办中小学招聘教师92人(编制)考前自测高频考点模拟试题及一套完整答案详解
- 2025湖南永州市零陵区第二批公开引进急需紧缺专业人才(医疗岗9人)模拟试卷及答案详解参考
- 安全培训教师含义课件
- 2025年后链轮项目合作计划书
- 2025江西南昌市青山湖区招聘社区工作者(专职网格员)45人模拟试卷及答案详解一套
- Indazole-Standard-生命科学试剂-MCE
- IID432-生命科学试剂-MCE
- H-PEG6-VH4127-NH2-生命科学试剂-MCE
- 医院院内急会诊制度
- TSDPIA 05-2022 宠物猫砂通用技术规范
- 动力管道培训
- GB/T 11446.9-2013电子级水中微粒的仪器测试方法
- 热力学发展史概述讲课稿
- 教学配套课件:二维动态图形设计基础
- 预防电信诈骗网络诈骗
- 督脉灸参考课件
- 2022版《科学》课程标准考试试题及答案(四套)
- 建筑节能-课件
- Unit5DevelopingideasThesecretlanguageofplants课件-高中英语外研版(2019)选择性必修第一册
评论
0/150
提交评论