1、1实验四 复杂查询一、实验目的掌握两个表以上的连接查询的应用,包括嵌套查询。二、实验内容 (1)查询比“林红” 年纪大的男学生信息。select * from Studentwhere Sex = 男 and YEAR(Birth)-(select YEAR(Birth) from Student where Sname =林红) 051 and Birth (select MAX(Grade)from SC where cno=002)order by Grade desc(11)检索选修3门以上课程的学生的学号、总成绩(不统计不及格的课程) ,并要求按总成绩的降序排列出来。select S
2、no,sum(grade) as 总成绩7from SCwhere Sno in(select Sno from SCgroup by Snohaving count(*)3) and Grade=60group by Snoorder by 总成绩 desc(12)检索多于3名学生选修的并以3结尾的课程号的平均成绩。select avg(Grade) as 平均成绩from SCwhere Cno like %3group by Cnohaving count(Cno)3(13)检索最高分与最低分之差大于5分的学生的学号、姓名、最高分、最底分。select distinct SC.Sno 学
3、号, Sname 姓名,max(grade) as 最高分,min (grade)as 最低分from Student,SC8where SC.Sno=Student.Snogroup by SC.Sno,Snamehaving max(grade)-min(grade)5(14)外连接对实验二中的表6和表7做一个外连接查询,显示每门课程的课号、课名、选修该门课的学号、成绩,没有同学选修的课程(如Visual_Basic)也要在查询结果中。select c.Cno 课号,Cname 课名, Sno 学号, Grade 成绩from Course c left outer join SCon (
4、c.Cno=SC.Cno)(15)创建一个表Student_other,结构同Student,输入若干记录,部分记录和Student表中的相同。创建过程:create table Student_other(Sno char(8) primary key,Sname varchar(8) not null,Sex char(2) not null,Birth smalldatetime not null,9Classno char(3) not null,Entrance_date smalldatetime not null,Home_addr varchar(40),Sdept char(2) not null,Postcode char(6) )随意输入几条Student表中没有的信息,完成创建a.查询同时出现在Student表和Student_other表中的记录select * from student_other so,Student swhere so.Sno=s.Sno10b. 查询Student表和Student_other表中的全部记录select * from studentunionselect * from student_other(16) (选作)创建一个数据库 Student_info_other,参数自定。创建过程:新建数据库