已阅读5页,还剩12页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
一 设有一数据库 包括四个表 学生表 Student 课程表 Course 成绩表 Score 以及教师信息表 Teacher 四个表的结构分别如表 1 1 的表 一 表 四 所示 数据如表 1 2 的表 一 表 四 所示 用 SQL 语句创建四个表并完成相 关题目 表 1 1 数据库的表结构 表 一 Student 学生表 属性名数据类型可否为空含义 Snovarchar 20 否学号 主码 Snamevarchar 20 否学生姓名 Ssexvarchar 20 否学生性别 Sbirthdaydatetime 可学生出生年月 Classvarchar 20 可学生所在班级 表 二 Course 课程表 属性名数据类型可否为空含义 Cnovarchar 20 否课程号 主码 Cnamevarchar 20 否课程名称 Tnovarchar 20 否教工编号 外码 表 三 Score 成绩表 属性名数据类型可否为空含义 Snovarchar 20 否学号 外码 Cnovarchar 20 否课程号 外码 DegreeDecimal 4 1 可成绩 主码 Sno Cno 表 四 Teacher 教师表 属性名数据类型可否为空含义 Tnovarchar 20 否教工编号 主码 Tnamevarchar 20 否教工姓名 Tsexvarchar 20 否教工性别 Tbirthdaydatetime 可教工出生年月 Profvarchar 20 可职称 Departvarchar 20 否教工所在部门 表 1 2 数据库中的数据 表 一 Student SnoSnameSsexSbirthdayclass 108 曾华男 1977 09 0195033 105 匡明男 1975 10 0295031 107 王丽女 1976 01 2395033 101 李军男 1976 02 2095033 109 王芳女 1975 02 1095031 103 陆君男 1974 06 0395031 表 二 Course CnoCnameTno 3 105 计算机导论 825 3 245 操作系统 804 6 166 数字电路 856 9 888 高等数学 831 表 三 Score SnoCnoDegree 1033 24586 1053 24575 1093 24568 1033 10592 1053 10588 1093 10576 1013 10564 1073 10591 1083 10578 1016 16685 1076 16679 1086 16681 表 四 Teacher TnoTnameTsexTbirthdayProfDepart 804 李诚男 1958 12 02 副教授计算机系 856 张旭男 1969 03 12 讲师电子工程系 825 王萍女 1972 05 05 助教计算机系 831 刘冰女 1977 08 14 助教电子工程系 1 查询 Student 表中的所有记录的 Sname Ssex 和 Class 列 select Sname Ssex Class from Student 2 查询教师所有的单位即不重复的 Depart 列 select distinct Depart from teacher 3 查询 Student 表的所有记录 select from student 4 查询 Score 表中成绩在 60 到 80 之间的所有记录 select from Score where Degree between 60and 80 5 查询 Score 表中成绩为 85 86 或 88 的记录 select from Score where Degree 85 orDegree 86 or Degree 88 6 查询 Student 表中 95031 班或性别为 女 的同学记录 select from student where Class 95031 or Ssex 女 7 以 Class 降序查询 Student 表的所有记录 select from student order by Class desc 8 以 Cno 升序 Degree 降序查询 Score 表的所有记录 select from Score order by cno asc Degree desc 9 查询 95031 班的学生人数 select count from student whereclass 95031 10 查询 Score 表中的最高分的学生学号和课程号 子查询或者排序 select Cno sno from Score where degree in select MAX Degree from Score 11 查询每门课的平均成绩 select avg degree cno from Score group bycno 12 查询 Score 表中至少有 5 名学生选修的并以 3 开头的课程的平均分数 select AVG Degree from Score group by cnohaving count cno 5 and Cno like 3 13 查询分数大于 70 小于 90 的 Sno 列 Select Sno from Score where Degree between70 and 90 14 查询所有学生的 Sname Cno 和 Degree 列 select Sname Cno Degree from Student joinScore on Student Sno Score Sno 15 查询所有学生的 Sno Cname 和 Degree 列 select Cname Sno Degree from course joinScore on o So 16 查询所有学生的 Sname Cname 和 Degree 列 select Cname Sname Degree from course Score Student where Student Sno Score Sno andCo Score Cno 17 查询 95033 班学生的平均分 select avg degree from score student wherescore sno student sno and class 95033 18 假设使用如下命令建立了一个 grade 表 create table grade low int 3 upp int 3 rankchar 1 insert into grade values 90 100 A insert into grade values 80 89 B insert into grade values 70 79 C insert into grade values 60 69 D insert into grade values 0 59 E 现查询所有同学的 Sno Cno 和 rank 列 Select sno cno rank from score join gradeon score Degree between grade low and grade upp 19 查询选修 3 105 课程的成绩高于 109 号同学成绩的所有同学的记录 select from Score where cno 3 105 andDegree select degree from Score where cno 3 105 and Sno 109 20 查询 score 中选学多门课程的同学中分数为非最高分成绩的记录 select from score a where sno in Selectsno from score group by sno having count sno 1 and degree select degree from Score where Sno 109 and cno 3 105 22 查询和学号为 108 的同学同年出生的所有学生的 Sno Sname 和 Sbirthday 列 select Sno Sname Sbirthday from Studentwhere YEAR Sbirthday select YEAR sbirthday from Student where Sno 108 23 查询 张旭 教师任课的学生成绩 Select Degree from score where cno Selectcno from course where tno Select tno from teacher where tname 张旭 24 查询选修某课程的同学人数多于 5 人的教师姓名 Select tname from teacher where Tno selectTno from Course where Cno select Cno from Score group by Cno havingCOUNT 5 25 查询 95033 班和 95031 班全体学生的记录 select from Student where Class 95033 or Class 95031 26 查询存在有 85 分以上成绩的课程 Cno select distinct cno from score whereDegree 85 27 查询出 计算机系 教师所教课程的成绩表 select degree from score where Cnoin select cno from Course where Tno in select tno from Teacher where Depart 计算 机系 28 查询 计算机系 与 电子工程系 不同职称的教师的 Tname 和 Prof select Tname Prof from teacher where profnot in select prof from teacher where depart 计算机系 and prof in select prof from teacher where depart 电子工程系 29 查询选修编号为 3 105 课程且成绩至少高于选修编号为 3 245 的同学的 Cno Sno 和 Degree 并按 Degree 从高到低次 序排序 select Cno Sno Degree from Score whereCno 3 105 and Degree select MAX degree from Score where Cno 3 245 order by Degree desc 30 查询选修编号为 3 105 且成绩高于选修编号为 3 245 课程的同学的 Cno Sno 和 Degree select Cno Sno Degree from Score whereCno 3 105 and Degree select MAX degree from Score where Cno 3 245 31 查询所有教师和同学的 name sex 和 birthday select sname as name ssex as sex sbirthdayas birthday from Student union select tname tsex tbirthday from teacher 32 查询所有 女 教师和 女 同学的 name sex 和 birthday select sname as name ssex as sex sbirthdayas birthday from Student where Ssex 女 union select tname tsex tbirthday from teacherwhere tsex 女 33 查询成绩比该课程平均成绩低的同学的成绩表 Select degree from score a wheredegree 2 37 查询 Student 表中不姓 王 的同学记录 select from student where sname not like 王 38 查询 Student 表中每个学生的姓名和年龄 Selectsname YEAR GETDATE YEAR sbirthday as 年龄 from student 39 查询 Student 表中最大和最小的 Sbirthday 日期值 select MAX Sbirthday MIN Sbirthday fromStudent 40 以班号和年龄从大到小的顺序查询 Student 表中的全部记录 select from Student order by Class desc Sbirthday ASC 41 查询 男 教师及其所上的课程 Select tname cname from teacher join courseon teacher tno course tno and teacher tsex 男 42 查询最高分同学的 Sno Cno 和 Degree 列 select Sno Cno Degree from Score whereDegree in select MAX Degree from Score 43 查询和 李军 同性别的所有同学的 Sname Select sname from student wheressex select ssex from student where sname 李军 44 查询和 李
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 0808 商法测验试题及答案展示
- 2026农业科技园区规划与人才引进政策研究分析
- 2026中国智能交通信息服务行业市场供需分析及投资评估规划分析研究报告
- 2026中国智能仓储传感器网络部署与效率优化方案
- 2026食品加工无菌冷库行业市场供需现状及投资方向研判规划报告
- 2026中国青少年体育训练防护装备政策支持与市场培育策略报告
- 人工智能证券交易模型
- 高职建筑工程技术专业三年级《建筑钢结构构造》课程差异化教学设计
- 大学本科四年级经济学专业《区域经济协同创新:理论与模式》教学设计
- 小学数学三年级上册《分数的简单应用(二)》教学设计
- 2026年心理健康全科专任小学教师招聘考试笔试试题(含答案)
- 2026年新疆第三师图木舒克市高校毕业生“三支一扶”计划招募(347人)笔试参考试题及答案详解
- 2026年三支一扶考试综合基础知识考试卷及答案(六)
- 2026-2030中国减肥市场发展动向分析与未来营销创新策略研究报告
- 高标准农田建设项目监理服务方案投标文件(技术方案)
- 新生儿灌肠操作规范
- 医院供氧中心工作制度
- GB/T 46585-2025建筑用绝热制品试件线性尺寸的测量
- 工作中秘密管理暂行办法
- 童话故事创意写作训练教案
- GB/T 25606-2025土方机械产品识别代码系统
评论
0/150
提交评论