资源描述
单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,*,NO,NAME,SEX,AGE,CLASS,108,曾华,男,19,95033,105,匡明,男,20,95031,107,王丽,女,20,95033,101,李军,男,19,95033,109,王芳,女,22,95031,103,陆君,男,20,95031,CNO,CNAME,TNO,3-105,计算机导论,825,3-245,操作系统,804,6-166,数字电路,856,9-888,高等数学,831,TNO,NAME,SEX,AGE,PROF,DEPART,804,李诚,男,42,副教授,计算机系,856,张旭,男,35,讲师,电子工程,825,王萍,女,28,助教,计算机系,831,刘冰,女,25,助教,电子工程,NO,CNO,GRADE,103,3-245,86,105,3-245,75,109,3-245,68,103,3-105,92,105,3-105,88,109,3-105,76,101,3-105,64,107,3-105,91,108,3-105,78,101,6-166,85,107,6-166,79,108,6-166,81,学生表,课程表,教师表,成绩表,练习作业,(,1,)查询选修课程,3-105,且成绩在,60,到,80,之间的所有记录。,(,2,)查询成绩为,85,、,86,或,88,的记录。,(,3,)查询,95031,班的学生人数。,(,4,)查询至少有,5,名学生选修并以,3,开头的课程的平均成绩。,(,5,)查询最低分大于,70,,最高分小于,90,的,NO,列。,(,6,)查询,95033,班学生所选课程的平均分。,(,7,)查询选修,3-105,课程的成绩高于,109,号同学成绩的所有同学的记录。,(,8,)查询与学号为,108,的同学同岁的所有学生的,NO,、,NAME,和,AGE,。,(,9,)查询“张旭”教师任课的课程号,选修其课程学生的学号和成绩。,(,10,)查询选修其课程的学生人数多于,5,人的教师姓名。,(,11,)查询“计算机系”与“电子工程系”不同职称的教师的姓名和职称。,(,12,)查询选修编号为“,3-105”,课程且成绩至少高于选修编号为“,3-245”,课程的同学的,CNO,、,NO,、,GRADE,并按,GRADE,从高到低次序排列。,(,13,)查询选修编号为“,3-105”,课程且成绩高于选修编号为“,3-245”,课程的同学的,CNO,、,NO,、,GRADE,。,(,14,)列出所有教师和同学的,NAME,、,SEX,、,AGE,。,(,15,)查询成绩比该课程平均成绩低的学生的成绩表。,(,16,)列出所有任课教师的,NAME,和,DEPART,。,(,17,)列出所有未讲课教师的,NAME,和,DEPART,。,(,18,)列出至少有,2,名男生的班号。,(,19,)查询不姓“王”的学生记录。,(,20,)查询每门课最高分的学生的,NO,、,CNO,、,CRADE,。,(,21,)查询与“李军”同性别并同班的同学,NAME,。,(,22,)查询“男”教师及其所上的课程。,(,23,)查询选修“计算机导论”课程的“男”同学的成绩表。,(,24,)往基本表,Student,中插入一个学生元组(,张红,,,女,)。,(,25,)在基本表,SC,中删除尚无成绩的选课元组,(,26,)把选修数学课不及格的成绩全改为空值,(,27,)把低于总平均成绩的女同学成绩提高,5%,(,28,)在基本表,SC,中修改,1,号课程的成绩,若成绩小于等于,75,分时提高,5%,若成绩大于,75,时提高,4%,(,29,)查询“张旭”教师任课的课程号,选修其课程学生的学号和成绩。,(,30,)检索学号比李同学大,而年龄比他小的学生姓名。,-(1)查询选修课程3-105且成绩在60到80之间的所有记录。t,select st.no,st.name,st.age,st.sex,st.class,sc.grade,from student st,scores sc,where(st.no=sc.no and o=3105);,-(2)查询成绩为85、86或88的记录。,select st.no,st.name,st.class,sc.grade,from student st,scores sc,where(st.no=sc.no and(sc.grade=85 or sc.grade=86 or sc.grade=88);,-(3)查询95031班的学生人数。,select count(no),from student,where class=95031;,-(4)查询至少有5名学生选修并以3开头的课程的平均成绩。,SELECT cno,avg(grade)FROM SCORES,WHERE substr(cno,1,1)=3,GROUP BY CNO,HAVING COUNT(*)=5;,-(5)查询最低分大于70,最高分小于90的NO列。,select sc.no,from scores sc,student st,where st.no=sc.no,group by sc.no,having min(sc.grade)70 and max(sc.grade)(select grade,from scores,where cno=3105and no=109),and st.no=sc.no;,-(8)查询与学号为108的同学同岁的所有学生的NO、NAME和AGE。,select no,name,age,from student,where age=(select age,from student,where no=108);,-(9)查询“张旭”教师任课的课程号,选修其课程学生的学号和成绩。,select o,sc.no,sc.grade,from course co,scores sc,teacher t,where t.name=张旭 and t.tno=co.tno and o=o;,-(10)查询选修其课程的学生人数多于5人的教师姓名。,SELECT distinct t.name,from course co,teacher t,scores sc,where o=o and t.tno=co.tno and,o in(select o,from scores sc,course co,where o=o,group by o,having count(o)5);,-(11)查询“计算机系”与“电子工程系”不同职称的教师的姓名和职称。,select name,prof,from teacher,where depart=计算机系 or depart=电子工程,group by prof,name,-*(12)查询选修编号为“3-105”课程且成绩至少高于选修编号为“3-245”课程的同学的CNO、NO、GRADE并按GRADE从高到低次序排列。,select*,from scores,where cno=3105 and grade all(select grade,from scores,where cno=3245)order by grade desc;,-(13)查询选修编号为“3-105”课程且成绩高于选修编号为“3-245”课程的同学的CNO、NO、GRADE。,select*,from scores,where cno=3105 and grade all(select grade,from scores,where cno=3245);,-(14)列出所有教师和同学的NAME、SEX、AGE。,select student.name,student.sex,student.age,teacher.name,teacher.sex,teacher.age,from,student inner join(scores inner join(course inner join teacher on course.tno=teacher.tno),on o=o)on student.no=scores.no;,-(15)查询成绩比该课程平均成绩低的学生的成绩表。,select*,from scores sc,where grade=2;,-(19)查询不姓“王”的学生记录。,select*,from student,where name not in(select name from student where name like 王%);,-(20)查询每门课最高分的学生的NO、CNO、CRADE。,select*,from scores,where grade in(select max(grade)from scores group by cno);,-(21)查询与“李军”同性别并同班的同学NAME。,select name,from student,where sex in(select sex,from student,where name=李军)and class in(select class,from student,where name=李军),-(22)查询“男”教师及其所上的课程。,select name,cname,from teacher,course,where sex=男 and teacher.tno=course.tno;,-(23)查询选修“计算机导论”课程的“男”同学的成绩表。,select st.no,st.name,grade,from student st,course,scores,where st.sex=男 and ame=计算机导论 and o=o,and st.no=scores.no;,-(24)往基本表Student中插入一个学生元组(张红,女)。,insert into student,values(111,张红,女,20,95033);,commit;,-(25)在基本表SC中删除尚无成绩的选课元组,delete from scores,where grade=null,commit;,-(26)把选修数学课不及格的成绩全改为空值,update scores,set grade=null,where grade60,-(27)把低于总平均成绩的女同学成绩提高5%,update scores,set grade=grade*1.05,where grade(select avg(grade),from scores),select*from scores,-(28)在基本表SC中修改1号课程的成绩,若成绩小于等于75分时提高5%,若成绩大于75时提高4%,update scores,set grade=grade*1.05,where grade75 and cno=1;,(29)查询“张旭”教师任课的课程号,选修其课程学生的学号和成绩。,select o,sc.no,sc.grade,from course co,scores sc,teacher t,where t.name=张旭 and t.tno=co.tno and o=o;,-(30)检索学号比李同学大,而年龄比他小的学生姓名。,select name,no,age,from student,where no(select no from student where name=李)and,age(select age from student where name=李);,
展开阅读全文