数据库实验1-6参考答案 联系客服

发布时间 : 星期二 文章数据库实验1-6参考答案更新完毕开始阅读0be4002a0066f5335a812144

select count(distinct sno) from SC

(12)查询选修了“C05”课程的的学生成绩单,要求输出学号,姓名,成绩,结果按班级升序,成绩降序排列。

select student.Sno,Sname,Grade from student,SC where student.Sno=SC.Sno and Cno='C05' order by left(student.Sno,5) asc,Grade desc

(13)统计各门课程的成绩,要求输出课程代号,课程名,平均成绩,选修人数。(成绩为NULL值的不统计)

select course.Cno,Cname,avg(Grade),count(Sno) from course,Sc where course.Cno=SC.Cno and Grade is not null group by Course.Cno,Cname

(14)统计各门课程的不及格人数,要求输出课程代号,课程名,不及格人数。

select Course.Cno,Cname,count(Sno) from SC,Course where SC.Cno=course.Cno and Grade<60 group by Course.Cno,Cname

(15)查询选修平均成绩在75分以上的学生的学号,姓名,所在系。

select sc.sno,sname,sdept from student,sc where student.sno=sc.sno group by sc.sno,sname,sdept having avg(grade)>75 或:

select sno,sname,sdept from student where Sno in (Select Sno From SC Group By Sno Having Avg(Grade)>75)

(16)查询与“王大力”同一个系的学生的基本信息

select * from student where sdept in(select sdept from student where sname='王大力')

(17)查询选修平均分高于所有学生平均分的学生的学号,并按学号升序排列。

select student.Sno from student,SC where student.Sno=SC.Sno group by student.Sno having avg(Grade)>(select Avg(Grade) from SC) order by student.Sno asc

(18)查询未选修“VB”或“数据库基础”两门课的学生的学号,姓名,系名。(要

13

求用嵌套查询)

select sno,sname,sdept from student where sno not in(select sno from sc where cno in(select cno from course where cname in('VB','数据库基础'))) 或:

select sno,sname,sdept from Student where exists(

select * from Course where cname='VB' and not exists(

select * from SC where sno=Student.sno and cno=Course.cno and Course.cname!='数据库基础'))

(19)查询选修了全部课程的学生的学号,姓名,系名。

select sno,sname,sdept from student

where not exists(select * from course where not exists

(select * from sc where sno=student.sno and cno=course.cno ) ) 或:

select sno,sname,sdept from student

where sno in (select sno from sc group by sno having count(cno)=(select coount(*) from course))

(20)输出“高等数学”课程成绩前三名的学生的学号,姓名,系名

select top 3 student.sno,sname,sdept from student,sc,course where student.sno=sc.sno and sc.cno=course.cno and cname='高等数学' order by grade desc

四、实验小结

五、评阅成绩

实验预习20% 实验过程20% 实验结果30% 实验报告30% 总成绩 14

实验四 数据更新

一、实验目的

1、掌握SQL语言的数据更新操作

2、掌握SQL Server 2000企业管理器的数据导入和导出功能

二、实验预习

1、数据插入语句格式:

2、数据修改语句格式:

3、数据删除语句格式: 4、SQL Server中可进行批量数据导入和导出,可支持哪些格式的数据导入导出?(举常见格式类型)

三、实验内容和要求

(执行操作后,将语句填写在下面的空白处) 1、插入数据

(1)在学生表Student中插入数据:

Sno:9512102 Sname:刘晨 Ssex:男 Sage:20 Sdept:计算机系 insert into Student

values ('9512102','刘晨','男',20,'计算机系')

(2)在课程表Course中插入数据:

Cno:C06 Cname:数据结构 Ccredit:5 Semster:4 insert into Course(cno,cname,ccredit,semster) values ('C06','数据结构',5,4) 或:

insert into Course values ('C06','数据结构',5,4,null)

15

(3)在选课表SC中插入95211班学生选修C04的选课信息。

提示:插入的数据的Sno从Student表中查询而来,插入的Cno为“C04” insert into SC(sno,Cno)

select sno,'c04' from Student where sno like '95211%'

(4)查询高等数学的成绩,包括学号,成绩,并按学号升序排序。将查询的结果输出到一个名为gs_cj的表中。 select sno,grade into gs_cj

from sc join course on sc.cno=course.cno and cname='高等数学' order by sno

(5)将SC表中“C05”课程的选课记录输出至一个新表中,表名为Gs01。 select * into Gs01

from sc where cno='c05'

2、修改数据

(1) 将所有学生的年龄增加1岁。 update student set sage=sage+1

(2)修改“9512101”学生的“C01”课程成绩为85。 update sc set grade=85

where sno='9512101' and cno='c01'

(3)修改“9531102”学生的“C01”课程成绩为70。 update sc set grade=70

where sno='9531102' and cno='c01'

(4)将所有平均分为75分以上的学生的各门课成绩在原来基础上增加1%。 update sc set grade=grade*1.01 where sno in

(select sno from sc group by sno having avg(grade)>=75)

3、删除数据

(1)删除“9531102”学生“C05”课程的成绩记录 delete from sc where sno='9531102' and cno='c05'

(2)删除所有课程为“C05”的选课记录 delete from sc where cno='c05'

16