将学习了数据库课程的学生成绩加5分。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
①将学习了数据库课程的学生成绩加5分。
update sc
set grade=grade+5
where cno=
( select cno
from course
where cname='数据库');
select *
from sc 执行后为:
②将计算机系学习了2号课程的学生成绩置0。
update sc
set grade=0
where cno=2 and sno=
( select sno
from student
where sdept='CS');
select *
from sc 执行后为:
③将ZKT的数据库成绩改为85。
update sc
set grade=85
where sno=
(select sno
from student
where sname='ZKT')
and cno=
(select cno
from course
where cname='数据库');select *
from sc 执行结果后为:
④将选修了2号课程且成绩为空的选课记录删除。
delete
from sc
where cno=2 and grade=NULL;
select *
from sc 执行后为:
⑤从课程表中删除在选课表中没有选课记录的课程记录。
delete
from course
where not exists
(select *
from sc
where o=o)
select *
from course 执行后为:
⑥删除计算机系学生选修了数据库课程的选课记录。
delete
from sc
where cno=
( select cno
from course
where cname='数据库')and sno in
(select sno
from student
where sdept='CS')
select * from sc;
执行结果后为:
⑦求各系的系名及男女生人数并将结果保存到另一个表
中。
create table s1(sdept char (20),ssex char(2),c1 int) insert into s1
select sdept, ssex,count(ssex)
from student
group by sdept,ssex;
执行查询:
select * from s1
⑧将平均成绩80分以上的学生的学号,选学的课程数和
平均成绩保存到另一个表中。
create table s2
(sno int Not Null,
c int,
avgage int);
insert into s2
select sno,count(cno),avg(grade)
from sc
group by sno
having avg(grade)>80
执行查询:
select * from s2
⑨创建一个视图,求各门课程的课程号、平均分、最高
分。
create view fen(cno, gavge, zuida)
as
select cno,avg(grade), max(grade)
from sc
group by cno
执行查询:
select * from fen; ⑩创建一个视图,求选修了2号课程且成绩高于该门课程平均分的学生学号和成绩。
create view chengji
as
select sno,grade
from sc
where cno=2 and grade>
(select avg(grade)
from sc
where cno=2)
执行查询:
select * from chengji。