4实验四-复杂查询.doc

上传人:hw****26 文档编号:2123934 上传时间:2019-04-29 格式:DOC 页数:11 大小:689KB
下载 相关 举报
4实验四-复杂查询.doc_第1页
第1页 / 共11页
4实验四-复杂查询.doc_第2页
第2页 / 共11页
4实验四-复杂查询.doc_第3页
第3页 / 共11页
4实验四-复杂查询.doc_第4页
第4页 / 共11页
4实验四-复杂查询.doc_第5页
第5页 / 共11页
点击查看更多>>
资源描述

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,参数自定。创建过程:新建数据库

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育教学资料库 > 课程笔记

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。