1、现在有一教学管理系统,具体的关系模式如下:Student (no, name, sex, birthday, class)Teacher (no, name, sex, birthday, prof, depart)Course (cno, cname, tno)Score (no, cno, degree)其中表中包含如下数据:Course表:Score 表:Student 表:Teacher 表:根据上面描述完成下面问题:( 注意 :注意保存脚本,尤其是DDL和DML,以便进行数据还原)DDL1. 写出上述表的建表语句。2. 给出相应的INSERT语句来完成题中给出数据的插入。单表查询3.
2、 以 class 降序输出 student 的所有记录(student 表全部属性)命令:select * from Student order by class desc;4. 列出教师所在的单位 depart(不重复) 。命令:select distinct depart from Teacher;5. 列出 student 表中所有记录的 name、sex 和 class 列命令:select name,sex,class from Student;6. 输出 student 中不姓王的同学的姓名。命令:select name from Student except select nam
3、e from Student where name like 王%;或select name from Student where name not like 王%;7. 输出成绩为 85 或 86 或 88 或在 60-80 之间的记录(no,cno,degree)命令:select no,cno,DEGREE from Score where degree=85 or degree=86 or degree=88 or degree between 60 and 80;8. 输出班级为 95001 或性别为女 的同学(student 表全部属性)命令:select * from Stude
4、nt where class=95001 or sex=女;9. 以 cno 升序、degree 降序输出 score 的所有记录。 (score 表全部属性)命令:select * from Score order by cno asc,degree desc;10. 输出男生人数及这些男生分布在多少个班级中命令:select COUNT(*),count(distinct class) from Student where sex=男 ;11. 列出存在有85分以上成绩的课程编号。命令:select distinct cno from Score where degree85;12. 输出
5、 95001 班级的学生人数命令:select COUNT(*) from Student where class=95001;13. 输出3-105号课程的平均分命令:select avg(cast(degree as float) from Score where cno=3-105;14. 输出 student 中最大和最小的 birthday 日期值命令:select MAX(birthday),MIN(birthday) from Student;15. 显示 95001 和 95004 班全体学生的全部个人信息(不包括选课) 。 (student 表全部属性)命令:select *
6、 from Student where class=95001 or class=95004;聚合查询16. 输出至少有 5 个同学选修的并以 3 开头的课程的课程号,课程平均分,课程最高分,课程最低分。命令:select cno,avg(cast(degree as float),MAX(degree),MIN(degree) from Score where cno like 3% group by cno having COUNT(cno)5;或者:select cno,AVG(cast(DEGREE as float),MAX(degree),MIN(DEGREE) from Scor
7、e group by cno having COUNT(cno)=5 and cno like 3%17. 输出所选修课程中最低分大于 70 分且最高分小于 90 分的学生学号及学生姓名命令:select Student.no,name from Student join Score on Student.no=Score.no group by Student.no,name having MAX(Score.degree)70;18. 显示所教课程选修人数多于 5 人的教师姓名命令:select name from Teacher join Course on Teacher.no=Cou
8、rse.tno where Co in(select cno from Score group by cno having COUNT(So)5);19. 输出95001班级所选课程的课程号和平均分命令:select cno,avg(cast(degree as float) from Score where no in(select no from Student where class=95001) group by cno;或者:select cno,AVG(cast(degree as float) from Score join Student on Score.no=Student
9、.no group by cno,class having class=9500120. 输出至少有两名男同学的班级编号。命令:select class from Student where sex=男 group by class having COUNT(class)=2;或者:select a.class from (select * from Student where sex=男) a group by a.class having COUNT(a.class)=2多表查询21. 列出与 108 号同学同年出生的所有学生的学号、姓名和生日命令:select no,name,birth
10、day from Student where year(birthday) =(select year(birthday) from Student where no=108);或者:select b.no,b.name,b.birthday from Student a join Student b on datediff(YEAR,a.birthday,b.birthday)=0 and a.no=10822. 列出存在有 85 分以上成绩的课程名称命令:select cname from Course where cno in (select distinct cno from Scor
11、e where degree85);或select distinct cname from Course join Score on Co=So where degree85;23. 列出“计算机系”教师所教课程的成绩表(课程编号,课程名,学生名,成绩) 。命令:select Co,cname,Student.name,DEGREE from Teacher join Course on Teacher.no=Course.tno join Score on Co=So join Student on Score.no=Student.no where Teacher.depart=计算机系
12、;24. 列出所有可能的“计算机系”与“电子工程系”不同职称的教师配对信息,要求输出每个老师的姓名(name)和(职称)命令:select a.name,a.prof,b.name,b.prof from (select name,prof,depart from Teacher where depart=计算机系 or depart=电子工程系) a join (select name,prof,depart from Teacher where depart=电子工程系 or depart=计算机系 ) b on not a.prof=b.prof and not a.depart=b.d
13、epart;25. 列出所有处于不同班级中,但具有相同生日的学生,要求输出每个学生的学号和姓名。 (提示:使用 datediff函数,具体用法可以参考:http:/ a.no,a.name,b.no,b.name from Student a join Student b on not a.class=b.class and a.birthday=b.birthday;26. 显示张三教师任课的学生姓名,课程名,成绩命令:select Student.name,cname,DEGREE from Teacher join Course on Teacher.no=Course.tno join
14、 Score on Co=So join Student on Score.no=Student.no where Teacher.name=张三;27. 列出所讲课已被选修的教师的姓名和系别命令:select distinct name,depart from Teacher join Course on Teacher.no=Course.tno join Score on Co=So;28. 输出所有学生的name、no和degree。 (degree为空的不输出和为空的输出两种情况) 。命令:select name,Student.no,DEGREE from Student left
15、 join Score on Student.no=Score.no;select name,Student.no,DEGREE from Student join Score on Student.no=Score.no;29. 列出所有任课教师的name和depart 。 (从课程选修和任课两个角度考虑)命令:select distinct name,depart from Teacher join Course on Teacher.no=Course.tno;select distinct name,depart from Teacher join Course on Teacher.no=Course.tno join Score on Co=So;30. 输出男教师所上课程名称。命令:select cname from Teacher join Course on Teacher.no=Course.tno where Teacher.sex=男 ;
Copyright © 2018-2021 Wenke99.com All rights reserved
工信部备案号:浙ICP备20026746号-2
公安局备案号:浙公网安备33038302330469号
本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。