图5-9
(3) 查询“大学计算机基础”课程考试成绩前三名的学生姓名和成绩。 select st_info.st_id,st_name,score from st_info
inner join s_c_info on st_info.st_id=s_c_info.st_id inner join c_info on s_c_info.c_no=c_info.c_no and c_name='大学计算机基础'
图5-10
(4) 将s_c_info中的score列的值转为等级制输出,即60分以下显示为“不及格”,60~69分显示“及格”,70~79分显示“中等”,80~81显示“良好”,90~100显示“优秀”。要求输出学号、姓名、课程名、成绩等级。(提示:
6 / 13
在select字句中使用case…when…end语句) select st_info.st_id,st_name,c_name,成绩等级= case
when score>=90 then'优秀' when score>=80 then'良好' when score>=70 then'中等' when score>=60 then'及格' when score<60 then'不及格' end
from s_c_info,st_info,c_info
where st_info.st_id=s_c_info.st_id and c_info.c_no=s_c_info.c_no
图5-11
(二)SQL的增删改功能
在实验四建立的studb数据库中,写SQL语句实现增删改功能。 1.在S表中增加如下记录:
图5-12
7 / 13
insert S
values('s3','张明华','男','1995/08/21 00:00:00.000','MA_数学','530.0','浙江杭州',NULL)
图5-13
图5-14
2. 在C表中将课程名为“数据库”的学分更改为3。 update C set ccredit='3' where cname='数据库'
图5-15
图5-16
3.删除S表中S2的学生记录,请问是否能删除,为什么,要如何操作。 能删除
delete from S where sno='S2'
8 / 13
图5-17
图5-18
图5-19
图5-20
(三)索引
1.在studb数据库中,分别用对象资源管理器和SQL语言定义索引
在对象资源管理器中,在T表的tname列上中建立聚集索引ix_tname,降序。查看
9 / 13
聚集的效果。
图5-21
图5-22
1.使用SQL语言定义TC表的(tno,cno)列上的复合索引ix_tc,tno列设为升序,cno列设为降序
先增加cno列,再删除聚集索引ix_tname。 create clustered index ix_tc
10 / 13