实验二 - 数据的查询、更新(2)
实验二 数据的查询、更新 徐龙琴设计制作
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 Cn …… 此处隐藏:1761字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [法律文档]苏教版七年级语文下册第五单元教学设计
- [法律文档]向市委巡视组进点汇报材料
- [法律文档]绵阳市2018年高三物理上学期第二次月考
- [法律文档]浅析如何解决当代中国“新三座大山”的
- [法律文档]延安北过境线大桥工程防洪评价报告 -
- [法律文档]激活生成元素让数学课堂充满生机
- [法律文档]2014年春学期九年级5月教学质量检测语
- [法律文档]放射科标准及各项计1
- [法律文档]2012年广州化学中考试题和答案(原版)
- [法律文档]地球物理勘查规范
- [法律文档]《12系列建筑标准设计图集》目录
- [法律文档]2018年宁波市专技人员继续教育公需课-
- [法律文档]工会委员会工作职责
- [法律文档]2014新版外研社九年级英语上册课文(完
- [法律文档]《阅微草堂笔记》部分篇目赏析
- [法律文档]尔雅军事理论2018课后答案(南开版)
- [法律文档]储竣-13827 黑娃山沟大开挖穿越说明书
- [法律文档]《产品设计》教学大纲及课程简介
- [法律文档]电动吊篮专项施工方案 - 图文
- [法律文档]实木地板和复合地板的比较
- 探析如何提高电力系统中PLC的可靠性
- 用Excel函数快速实现体能测试成绩统计
- 教师招聘考试重点分析:班主任工作常识
- 高三历史选修一《历史上重大改革回眸》
- 2013年中山市部分职位(工种)人力资源视
- 2015年中国水溶性蛋白市场年度调研报告
- 原地踏步走与立定教学设计
- 何家弘法律英语课件_第十二课
- 海信冰箱经销商大会——齐俊强副总经理
- 犯罪心理学讲座
- 初中英语作文病句和错句修改范例
- 虚拟化群集部署计划及操作流程
- 焊接板式塔顶冷凝器设计
- 浅析语文教学中
- 结构力学——6位移法
- 天正建筑CAD制图技巧
- 中华人民共和国财政部令第57号——注册
- 赢在企业文化展厅设计的起跑线上
- 2013版物理一轮精品复习学案:实验6
- 直隶总督署简介




