第一范文网 - 专业文章范例文档资料分享平台

数据库实验1-6参考答案

来源:用户分享 时间:2025/5/22 19:27:05 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

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

搜索更多关于: 数据库实验1-6参考答案 的文档
数据库实验1-6参考答案.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c0gpa81mzxi9kfa251dtw_4.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top