实验内容(注意,以下“2020***,吴***”请根据自己实际表值定)
1、附加或还原第二次实验的数据库。
2、完成以下语句的编写(以下题目中,条件的具体取值可以自定义)
1)查询指定学号的学生的所有课程的课程号,成绩
2)查出所有学生的学号,姓名,选课名称及成绩
3)查出所有有“大学英语一”成绩的学生姓名
4)查询学号为“2020***”的学生的所有课程的课程号,课程名,学分和成绩
5)查出所有的“高级语言程序设计”课程的不及格学生的学号
6)查询所有比“2020&***”同学年龄小的学生信息
7)统计“吴**”同学的平均成绩
8)查出所有平均成绩比“吴**”同学的高的学生信息
9)统计“数据库”课程的平均成绩
10)统计所有“数据库”课程成绩比“数据库”课程的平均成绩高的所有学生名单
11)参照10)完成统计所有“数据库”课程成绩比“数据库”课程的平均成绩低的所有学生名单
12)查出所有没有“大学英语一”成绩的学生名单
一、原有的数据表
1、class
包含classno(班级号)、classinfo(班级名)
2、course
包含cno(课程号)、cname(课程名)、credit(学分)
3、score
包含sno(学生号)、cno(课程号)、sscore(课程成绩)
4、student
包含sno(学号)、sname(学生姓名)、classno(班级号)、sbrithday(学生生日)、ssex(学生性别)
二、题目解答
1)查询指定学号的学生的所有课程的课程号,成绩
SELECT sno,CNO,sscore
FROM score
where sno = 945
2)查出所有学生的学号,姓名,选课名称及成绩
select student.sno,sname,cname,sscore
from course,score,student
where student.sno = score.sno and score.cno = course.cno
3)查出所有有“大学英语一”成绩的学生姓名
select sname
from student
where (sno in (select sno
from score
where cno = (select cno
from course
where cname = '大学英语一')))select
4)查询学号为“2020***”的学生的所有课程的课程号,课程名,学分和成绩
course.cno,cname,credit,sscore
from course,score,student
where student.sno = 2020210985 and student.sno =score.sno and score.cno =course.cno
5)查出所有的“高级语言程序设计”课程的不及格学生的学号
select sno as 学号
from score
left outer join course
on score.cno=course.cno
where course.cname='高级语言课程设计' and score.sscore<60
6)查询所有比“2020&***”同学年龄小的学生信息
select *
from student
where sbrithday>'2002.03.24'
7)统计“吴**”同学的平均成绩
select avg(sscore) as avgscore
from score
where (sno in (select sno
from student
where sname ='妙'))
8)查出所有平均成绩比“吴**”同学的高的学生信息
select student.sno,student.sname,student.classno,student.sbrithday,student.ssex
from student ,score
where student.sno=score.sno
group by student.sno,student.sname,student.classno,student.sbrithday,student.ssex
having AVG(score.sscore)>(select AVG(sscore) from score,student where sname='妙' and student.sno=score.sno)
9)统计“数据库”课程的平均成绩
select avg(sscore) as avgscore
from score
where cno='C001'
10)统计所有“数据库”课程成绩比“数据库”课程的平均成绩高的所有学生名单
select sname
from score,student
where score.sno=student.sno and cno = 'C001'
and sscore > (select avg(sscore) as avgscore
from score
where cno='C001')
11)参照10)完成统计所有“数据库”课程成绩比“数据库”课程的平均成绩低的所有学生名单
select sname
from score,student
where score.sno=student.sno and cno = 'C001'
and sscore < (select avg(sscore) as avgscore
from score
12)查出所有没有“大学英语一”成绩的学生名单
select sname
from student
where (not exists(select *
from score
where sno = student.sno and cno = 'C004'))