同济大学
《数据库技术及应用》
实验报告
实验报告题目:
SQL
数据查询
姓名: 杨雪纯 学号: 1257086 年级: 大二 专业:工商管理(职教师资) 指导教师: 袁科萍 日期: 2014 年 04 月 20 日
一、 实验目的
学会SQL数据查询 二、 实验内容 实验题目:
1.列出不及格记录的学生名单。
Select distinct * from student,sc where student.snum=sc.snum and score<60
2.列出选修了计算机系课程的学生姓名和年龄。
Select sname,(year(getdate())-year(birthday)) as age from student where snum in(select snum from sc
where secnum in(select secnum from sections where cnum in(select cnum from course where dept='计算机系')))
3.检索选修了数据库应用课程的学生姓名和系别。 Select sname,dept from student where snum in(select snum from sc
where secnum in(select secnum from sections where cnum in(select cnum from course where cname = '数据库应用')))
4.选修了所有课程的名单。 select * from student
where snum in( select snum from sc
group by snum having count(*)>=(select count(*) from course ))
5.检索每门课程成绩都在80分以上的学生名单。
Select distinct * from student where snum not in(select snum from sc where score<80 )
6.检索获奖学金的学生名单(每门课程在80分以上,平均成绩在90分以上)。 Select distinct * from student
where snum not in (select snum from sc
group by snum having avg(score)<90 or min(score)<80 )
7.检索选修了“大学英语”的学生名单和成绩,并按成绩从高到底排列。
Select sname ,score
from student,sc,sections,course where student.snum=sc.snum and sc.secnum=sections.secnum and sections.cnum=course.cnum and course.cname='大学英语' order by score desc
8.统计每门课程的选修人数,输出列名为课程号、人数。 select sections.cnum as 课程号,count(*) as 选课人数 from sections,sc
where sc.secnum=sections.secnum group by sections.cnum
9.查询选修了数据库应用、没有选修高等数学的学生姓名和系别。 Select student.sname,student.dept from student,sc,sections,course where student.snum=sc.snum and sc.secnum=sections.secnum and sections.cnum=course.cnum and course.cname = '数据库应用'
and student.snum not in(select snum from sc where secnum in(select secnum from sections where cnum in(select cnum from course where cname='高等数学')))
10.检索使用高等教育出版社出版的教材的课程名。
select cnum from course where textbook like'%高等教育出版社%'
11.统计所有课程的最高成绩、最低成绩和平均成绩。 Select course.cnum,cname, max(score) as 最高成绩, min(score) as 最低成绩, avg(score) as 平均成绩 from sc,sections,course
where sc.secnum in(select secnum from sections where sections.cnum = course.cnum) group by course.cnum,cname
12.统计每门课程的选课人数及不及格人数。 Select course.cnum, count(*) as 选课人数,
sum(1-score/60) as 不及格人数 from course,sections,sc
where sections.cnum=course.cnum and sc.secnum=sections.secnum group by course.cnum
13.查询土木工程系、交通工程系和城市规划系的学生学号和姓名。 Select snum,sname,dept from student
where student.dept='土木工程' or student.dept='交通工程' or student.dept='城市规划'
以下题目用集合运算符完成查询操作:
14.查询选修了数据库应用或选修了多媒体的学生学号。
Πsnum(σcname=’数据库应用’ or cname=’多媒体’(sc∞section∞course)) 15.查询计算机系且年龄不大于19岁的学生信息。
σdept=’计算机系’ and val(year(getdate())-year(birthday))<=19 (student∞sc∞section∞course))
16.查询计算机系且年龄大于
19岁的学生信息。
σdept=’计算机系’ and val(year(getdate())-year(birthday))>19 (student∞sc∞
section∞course))
三、 实验体会或收获(有感而发,没有体会也可以不写)
好难啊、难啊、啊??