数据库基础练习题解答 下载本文

--1、显示系部编号为“”的系部名称! select departname as '系部名称' from department where departno='03'

--2、查询系部名称中含有“工程”两个字的系的全名。 select departname '系部名称' from department

where departname like'%工程%'

--3、查询共有多少个系部。 select departname '系部名称' from department

compute count(departname)

--4、查询“01”年级共有多少个班级。 select count(classname) as '班级总数' from class

where classname like'01%'

--5、查询在“周二晚”上课的课程名称和教师。 select couname as '课程名称',teacher as '教师' from course

where schooltime='周二晚'

--6、查询姓“张”、“陈”、“黄”同学的的基本信息,要求按照姓名降序排序。 select * from student

Where stuname like'张%' or stuname like'陈%' or stuname like'黄%'

order by stuname desc

--7、按系部统计课程的平均报名人数,要求显示系部编号、平均报名人数。

select departno '系部编号',avg(willnum) '平均报名人数'

from course group by departno

--8、按系部统计课程的平均报名人数,要求显示系部名称、平均报名人数。

select departname '系部名称',avg(willnum) '平均报名人数'

from course,department

where course.departno=department.departno group by departname

--9、统计各系的班级数,要求显示系部编号、系部名称、班级数量。

select class.departno '系部编号',departname '系部名称',count(classname) '班级数量' from class,department

where class.departno=department.departno group by class.departno,departname

--10、查询“甘蕾”同学选修的课程名、学分、上课时间、志愿号,按志愿号排序查询结果。

select couname '课程名',credit '学分',schooltime '上课时间',willorder '志愿号' from course,stucou,student

where course.couno=stucou.couno and student.stuno=stucou.stuno and stuname='甘蕾' order by willorder

--11、显示“电子商务班”班的选修报名结果。要求有学号、姓名、课程编号、

--课程名称、志愿号,并按学号、志愿号排序。

select student.stuno '学号',stuname '姓名',stucou.couno '课程编号',couname '课程名称',willorder '志愿号'

from student,course,stucou,class where course.couno=stucou.couno and student.stuno=stucou.stuno and class.classno=student.classno and classname='00电子商务'

order by student.stuno,willorder

--12、学号为“”的学生第一志愿报名选修“”这门课程,请在数据库中进行处理。 insert stucou

values ('00000025','001','1','报名',NULL)

--13、删除学号为“00000025”的学生的选课报名信息。 delete stucou

where stuno='00000025'

--14、将“多媒体”班级“杜晓静”同学的名字修改为“杜小静”。 update student set stuname='杜小静' from class,student

where class.classno=student.classno and classname='00多媒体' and

stuname='杜晓静'

--15、“电子商务”班的“林斌”同学申请将已选修的“网络信息检索原理与技术”课程修改为“Linux操作系统”。 update stucou set

couno=(select

couno

from

course

where

couname='Linux操作系统')

from course,stucou,student,class where course.couno=stucou.couno and student.classno=class.classno and stucou.stuno=student.stuno and

classname='00电子商务' and stuname='林斌' and couname='网络信息检索原理与技术'