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

实验二 - 数据的查询、更新(2)

来源:网络收集 时间:2019-08-17 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

实验二 数据的查询、更新 徐龙琴设计制作

select count(*) from student

2)查询选修了课程的学生人数

select count(distinct Sno) from SC

3)计算选2号课程的学生平均成绩

select AVG(Grade) from SC where Cno='2'

4)查询选修2号课程的学生最高分数

select MAX(Grade) from SC where Cno='2'

5)求各个课程号及相应的选课人数

select Cno, COUNT(Sno) from SC group by Cno

6)查询选修了2门以上的课程的学生学号 select Sno from SC group by Sno having count(*)>2

7)查询每个学生及其选修课程的情况 select Student.Sno,Cname from SC,Course,Student where Student.Sno=SC.Sno and

Course.Cno=SC.Cno

8)查询每一门课的间接先修课(即先修课的先修课)

select first.Cno, second.Cpno from Course first,Course second where first.Cno=second.Cno

9)查询选修2号课程且成绩在90分以上(包括90分)的所有学生。

select Student.Sno,Sname from Student,SC

where Student.Sno=SC.Sno and SC.Grade>=90 and SC.Cno='2'

实验二 数据的查询、更新 徐龙琴设计制作

6. 用T-SQL语句完成下面的查询

1)查询与“刘晨”在同一个系学习的学生

select Sno,Sname,Sdept from Student where Sdept IN

(select Sdept from Student

where Sname='刘晨')

2)查询选修了课程名为“数学”的学生学号和姓名

select Student.Sno,Student.Sname from Course,Student,SC

where Student.Sno=SC.Sno and Course.Cno=SC.Cno

and Course.Cname='数学'

3)查询其它系中比信息系中某一学生年龄小的学生姓名和年龄 select Sname,Sage from Student where Sage

select Sage from Student where Sdept='IS')

and Sdept<>'IS'

4)查询其它系中比计算机系所有学生年龄都小的学生姓名及年龄

select Sname,Sage from Student where Sage

select Sage from Student where Sdept='CS')

and Sdept<>'CS'

5)查询所有选修了2号课程的学生姓名

select Sname from Student where EXISTS

(select * from SC

where Sno=Student.Sno and Cno='2')

6)查询没有选修3号课程的学生姓名

实验二 数据的查询、更新 徐龙琴设计制作

select Sname from Student where NOT EXISTS (select * from SC

where Sno=Student.Sno and Cno='3')

7、用T-SQL语句完成下面的复杂查询

1)至少选修刘老师所授课程中一门课程的女学生姓名

select Sname

from Student,Course,SC

where Student.Sno=SC.Sno and Course.Cno=SC.Cno

and Course.Teacher like'刘%'and Student.Ssex='女'

2)检索王同学不学的课程的课程号

select Cno from Course where Cno not in

(Select SC.Cno

from Student,SC,Course where Student.Sno=SC.Sno and Course.Cno=SC.Cno

and Student.Sname like '王%' )

select Cno from SC

where Cno not in(select Cno

from Student,SC

where Student.Sno=SC.Sno and Sname like'王%')

3)检索全部学生都选修的课程的课程号与课程名。

select Cno,Cname from Course where not exists (select *

from Student where not exists (select * from SC

where SC.Sno=Student.Sno and SC.Cno=Course.Cno)

)

4)检索选修课程包含刘老师所授课的学生学号。

实验二 数据的查询、更新 徐龙琴设计制作

select Sno from SC x

where not exists (

select * from Course

where Teacher like '刘%' and not exists ( select *

from SC y

where y.Cno=Course.Cno and y.Sno=x.Sno)

)

5)求选修课程号为2的学生的平均年龄。

Select AVG(Sage) from Student,SC

where Student.Sno=SC.Sno and SC.Cno='2'

6)求刘老师所授课程的每门课程的学生平均成绩。

Select Teacher ,Cname ,AVG(Grade) from Student,SC,Course

where Student.Sno=SC.Sno and Course.Cno=SC.Cno and Teacher like '刘%'

group by Teacher ,Course.Cno,Cname

7)检索学号比刘同学大,而年龄比他小的学生姓名。 select Sname from Student where Sno>(

select Sno from Student where Sname='刘同') and Sage<( select Sage from Student where Sname='刘同')

8)求年龄大于女同学平均年龄的男同学姓名和年龄。

select Sname,Sage from Student where Ssex ='男'and Sage>( select avg(Sage)

from Student where Ssex='女' )

实验二 数据的查询、更新 徐龙琴设计制作

9)求年龄大于所有女同学年龄的男学生姓名和年龄。

select Sname,Sage from Student

where Ssex='男' and Sage>all(

select Sage

from Student where Ssex='女')

10)检索每一门课程成绩都大于等于80分的学生学号、姓名和性别,并把检索到的值送往另一个已存在的基本表S(SNO,SNAME,SEX)。

select Sno SNO ,Sname SNAME,Ssex SEX into S from Student where Sno in (

select Sno from SC

where Grade>=80)

11)把选课数学课不及格的成绩全改为空值。

update SC set Grade ='' where Sno=(

select Sno from SC

where Grade<60 )

and Cno=(

select Cno from Course where Cname='数学')

12)把王同学的选课信息全部删去。

delete from SC where Sno=( select Sno from Student

where Sname like '王%')

13)把低于总平均成绩的男同学成绩提高5%。

update SC

set Grade=Grade*1.05 where Cno in (

select SC.Cno from SC,Student

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库实验二 - 数据的查询、更新(2)在线全文阅读。

实验二 - 数据的查询、更新(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/jiaoyu/681046.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: