2、找出供应商S1的供应情况
select sno,pno,qty from J_sanjian where sno='s1'
四、 主要仪器设备及耗材
PC机一台
五、 参考资料
卫琳 《SQL SERVER 2008数据库应用与开发教程》清华大学出版社 2011.6
一、 实验项目名称
数据库查询
南昌大学实验报告五
二、 实验目的 通过实验熟悉掌握数据库查询 三、 实验基本原理和内容
一、有一个“学生-课程”数据库,数据库中包括三个表: (1) “学生”表Student由学号(Sno)、姓名(Sname)、性别(Ssex)、年龄(Sage)、所在系(Sdept)五个属性组成,可记为: Student(Sno,Sname,Ssex,Sage,Sdept) Sno 为关键字。
(2) “课程”表Course由课程号(Cno)、课程名(Cname)、q任课教师(Cteacher)、学分(Ccredit)四个属性组成,可记为: Course(Cno,Cname, Cteacher,Ccredit) Cno为关键字。
(3) “学生选课”表SC由学号(Sno)、课程号(Cno)、成绩(Grade)三个属性组成,可记为: SC(Sno,Cno,Grade) (SNO, CNO) 为关键字。
用SQL语句完成下列操作:
1、建立一个“学生-课程”数据库,要求:表Student,表Course不少于4条记录。表SC不少于10条记录。(其中表Student要求输入包括考生本人姓名的记录一条)
2、查询考试成绩不及格的学生的学号, 课程号,成绩。
select sno,cno,grade from SC
where Grade<60
3、计算选修了1号课程的学生平均成绩,要求显示学号和平均成绩。
select sno,avg(grade)as avggrade from SC
where sno in (select sno from SC
where Cno='1') group by sno
4、查询每个系年龄最大的学生的学号,年龄。
select Sno,sage
from(select sdept,max(sage)as xsage from Student
group by sdept)as x,student
where x.Sdept=Student.Sdept and x.xsage=student.sage order by sno
5、查询没有选修过“李明”老师讲授课程的所有学生姓名。
select sname from student
where sno not in(select sno from sc
where cno=(select cno from course
where cteacher='李明'))
6、查询有二门以上(含两门)不及格课程的学生姓名
select sname
from student, (select Sno,COUNT(sno) as x from SCc
where Grade<60 group by sno) as y
where y.sno=Student.Sno and y.x>=2 (因所建表中并没有这种情况,故不截图)
7、查询既学过“1”号课程,又学过“2”号课程的所有学生姓名
select sname
from Student,SC
where student.sno =sc.sno and Cno='1' and Cno='2'
8、查询选修的课程的成绩大于该课程的平均成绩的所有学生姓名
select sname from student
where sno in (select sno
from SC,(select cno,AVG(grade) as x from SC
group by cno) as y where SC.Cno=y.Cno and SC.Grade>x group by sno)
相关推荐: