> 文章列表 > 实验四 子查询

实验四 子查询

实验四 子查询

第1关:子查询一

实验完成要求

根据代码区的提示,将查询数据的SQL语句书写在对应的代码区中。 注:请务必将select子句中出现的列名小写,顺序必须和题目要求一致

1、查询CS系学生选择的课程,列出学号,课程号,成绩

2、查询没有选C06(课程号)课程的同学的学号,姓名,性别

3、查询成绩最高的选课信息,列出学号,课程号和成绩。

select sno,cno,grade
from SC
where sno in(select sno from Student where sdept ='CS');
select sno,sname,ssex 
from Student 
where sno not in(select sno from SC where cno='C06');
select sno,cno,grade
from SC
where grade in(select max(grade) from SC);

第2关:子查询二

实验完成要求

根据代码区的提示,将查询数据的SQL语句书写在对应的代码区中。 注:请务必将select子句中出现的列名小写,顺序必须和题目要求一致 1、查询CS系没有选择'DB'课程学生的姓名,列出学生姓名。

2、查询‘DB’课程考最高分的选课信息。列出学号,课程号,成绩

select sname
from Student
where sdept ='CS' and sno not in(select sno from SC 
where cno in(select cno from Course
where cname='DB'));
select sno,cno,grade
from SC
where grade in (select max(grade) from SC where cno in(select cno from Course where Cname='DB'))andcno in (select cno from Course where Cname='DB')

第3关:子查询三

实验完成要求

根据代码区的提示,将查询数据的SQL语句书写在对应的代码区中。 注:请务必将select子句中出现的列名小写,顺序必须和题目要求一致 1、查询选修了先行课为'DB'的课程的学生,列出学生学号,姓名,性别,所在系。

select sno,sname,ssex,sdept
from Student
where sno in(select sno from SC where cno in(select cno from Course where cpno in(select cno from Course where cname='DB')))

第4关:带子查询的增删改

实验完成要求

根据代码区的提示,将SQL语句书写在对应的代码区中。

1、将'DB'课程不及格的成绩加5分。

2、删除'English'(课程名)课程CS系学生的选课记录。

3、为CS系添加必修课'c02'。(即:为CS系没有选c02课程的学生选c02课程)

update SC
set grade=grade+5
where grade<60 and cno in(select cno from Course where cname='DB')
delete from SC
where cno in (select cno from Course where cname='English') and sno in (select sno from Student where Sdept='CS');
insert into SC Select sno,'C02',nullfrom Student where Sdept='CS' and not exists (select * from SC where sno=Student.sno and cno='C02');