实验六 数据检索

来源:互联网 发布:应聘淘宝客服的表格 编辑:程序博客网 时间:2024/04/26 23:22

实验六 数据检索

 

1、实验目的

(1)掌握SELECT各子句的功能和检索数据的方法

(2)掌握WHERE子句中LINK、IN、BETEEN、IS等逻辑运算符的使用

(3)掌握COMOUTE语句和聚合函数的使用

2、实验内容

(1)查询所有课程的课程编号、课程名和学分

select courseno,cname,creditfrom course

(2)查询‘090501’班的所有学生的基本信息

select * from student wherestudent.classno='090501'

(3)查询student表中所有年龄大于20岁的男生的姓名和年龄

select sname ,  abs (datediff(YEAR,'2012-12-31',birthday))as '年龄'

 from student wherestudent.sex= N'' and abs (datediff(YEAR,'2012-12-31',birthday))>= 20

(4)查询选修课程且期末成绩不为空的学生人数

select count(*) from course,score,student

where course.courseno= score.courseno and

student.studentno = score.studentno and

course.type= N'选修'and

score.finalis not null

(5)查询Email使用126邮箱的所有学生的学号、姓名和电子邮箱地址。

select studentno,sname,Email

from student

where Email like'%@126.com'

(6)查询每名学生的学号、选修课程数目、总成绩、并将查询结果存放到生成的“学生选课统计表”中。

 

 

select student.studentno,student.NUM,grades

 

into 学生选课统计表

--,@num,grades

from student,course,score

where student.studentno= score.studentnoand

score.courseno= course.courseno

(7)查询score表中选修‘c05109’或‘05103’课程,并且课程期末成绩在90~100分之间的学生姓名和期末成绩。

 

select student.sname,score.final

from student,course,score

where student.studentno= score.studentnoand

score.courseno = course.courseno and

course.type= N'选修'and

score.final >= 90 and

score.final <= 100 and

 (

score.courseno = 'c05109' or

score.courseno = 'c05103'

)

(8)查询student表中所有学生的基本信息,查询结果按班级号classno升序排列,同一班级中的学生按入学成绩point降序排列。

select *from student

order by student.classnoasc , point desc

(9)查询选修‘c05109’课程,并且期末成绩在前5名的学生学号、课程号和期末成绩。

select top 5  student.studentno, score.courseno,score.final

from student,score,course

where student.studentno= score.studentnoand

--course.type= N'选修' and

score.courseno = course.courseno

and course.courseno= 'c05109'

order by score.finaldesc

(10)查询各班学生人数

select count(*) as'人数', classno

from student

group by classno

(11)查询各班期末成绩的最高分和最低分

select max(score.final)as 'max',min(score.final)as 'min' , classno

from student,score,course

where student.studentno= score.studentnoand

course.courseno = score.courseno

group by classno

(12)查询课程编号以‘c05’开头,被3名及以上学生选修且期末成绩的平均分高于75分的课程号、选修人数和期末成绩平均分,并按平均分降序排序。

 

(13)查询所有08级学生的期末成绩平均分,要求利用COMPUTE BY方法显示每一名学生的学生编号、课程号、期末成绩的明细表,以及期末成绩平均分的汇总表。

0 0