计算机科学系实验报告 (首页)
课程名称 数据库系统概论 班 级 11计算机
实验名称 数据库中数据的查询 指导教师
姓名 学 号 日 期 2013/10/14
一、实验目的
学会使用SQL语言进行各种类型的查询,理解各种查询的异同及相互之间的转换。
二、实验设备与环境
三、实验
内容
财务内部控制制度的内容财务内部控制制度的内容人员招聘与配置的内容项目成本控制的内容消防安全演练内容
、程序清单及运行结果
实验内容:
练习单
表
关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf
查询、嵌套查询、连接查询及集合查询
操作步骤:
1) 打开实验1建立的数据库
2) 在查询分析器中完成以下单表查询语句
查询全体学生的姓名及其出生年份
Select sname,2013-sage
From student;
查询选修了课程的学生学号(去掉重复行)
Select distinct sno
From sc
Where cno is not null;
查询年龄不在20~23岁之间的学生姓名、系别和年龄
SELECT sname,sdept,sage
from student
where sage not between 20 and 23;
查询既不是IS、MA,也不是CS系学生的姓名和性别
select sname,sdept
from student
where sdept not in ('CS','MA','IS');
查询所有姓刘的学生的姓名、学号和性别
select sname,sno,sage
from student
where sname like'刘%';
查询选修了3号课程的学生的学号及其成绩,结果按分数的降序排列
select sno,grade
from sc
where cno='3'
ORDER BY Grade asc;
计算1号课程的学生平均成绩
select avg(grade)
from sc
where cno='1';
查询选修了3门以上课程的学生学号
SELECT Sno
FROM SC
GROUP BY Sno
HAVING COUNT(*) >3;
3) 在查询分析器中完成以下连接查询语句
查询每个学生及其选修课程的情况(使用自然连接、外连接分别完成)
SELECT Student.sno ,sname ,ssex ,sdept ,cno ,grade
FROM Student ,SC
WHERE Student.sno =SC.sno ;
select student .sno ,sname,ssex,sage,sdept,cno,grade
from student left join sc on(student.sno=sc.sno);
查询每一门课的间接先修课
select first.cno,second.cpno
from course first,course second
where first .cpno =second .cno ;
查询选修2号课程且成绩在90分以上的所有学生
select student .sno ,sname
from student ,sc
where student .sno=sc.sno and sc.cno='2'and sc.grade >90;
查询每个学生的学号、姓名、选修的课程名及成绩
select student .sno ,sname,cname,grade
from student ,sc,course
where student .sno=sc.sno and sc.cno =course .cno ;
4) 在查询分析器中完成以下嵌套查询语句
查询与“刘晨”在同一个系学习的学生(使用嵌套查询、自身连接、比较运算符分别完成)
select sno ,sname ,sdept
from Student
where sdept in
(select sdept
from Student
where sname='刘晨');
select s1.sno,s1.sname,s1.sdept
from student s1,student s2
where s1.sdept=s2.sdept And
s2 .sname ='刘晨';
查询选修了课程名为“信息系统”的学生学号和姓名(使用嵌套查询、自然连接分别完成)
select sno,sname
from student
where sno in
(select sno
from sc
where cno in
(select cno
from course
where cname='信息系统'
)
);
select student .sno,sname
from student ,sc,course
where student.sno=sc.sno and
sc.cno=course .cno and
course.cname ='信息系统';
查询其他系中比信息系某一学生年龄小的学生姓名和年龄(使用ANY谓词、集函数分别完成)
select sname,sage
from student
where sage< any(select sage
from student
where sdept='cs')
and sdept <>'cs';
查询所有选修了1号课程的学生(使用比较运算符、IN、EXISTS分别完成)
select sname
from student
where exists
(select *
from sc
where sno=student .sno and cno='1');
查询没有选修1号课程的学生的姓名
select sname
from student
where not exists
(select *
from sc
where sno=student .sno and cno='1');
查询选修全部课程的学生姓名
select sname
from student
where not exists
(select *
from course
where not exists
(select *
from sc
where sno=student .sno
and cno =course.cno))
查询至少选修了学生95002选修的全部课程的学生号码
select distinct sno
from sc scx
where not exists
(select *
FROM sc SCY
where SCY.sno ='200215122'and
not exists
(select *
from sc scz
where scz .sno =scx.sno and
scz.cno =SCY.cno));
5) 在查询分析器中完成以下集合查询语句
查询计算机科学系的学生及年龄不大于19岁的学生并按学号排序(使用单表查询、集合查询分别完成)
Select *
from student
where sdept ='cs' and sage<=19
order by sno ;
select *
from student
where sage<=19
intersect
Select *
from student
where sdept ='cs'
order by sno ;
查询计算机科学系的学生及年龄不大于19岁的学生的差集
select *
from student
where sdept ='cs'
except
select *
from student
where sage <=19;
6) 在企业管理器可视化环境下重新完成2-5步骤的内容
四、实验结论、实验体会