ImageVerifierCode 换一换
格式:DOCX , 页数:14 ,大小:979.47KB ,
资源ID:4308098      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/4308098.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(实验报告第四次.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

实验报告第四次.docx

1、实验报告第四次实验名称 :SQL数据查询一、实验目的 :数据查询语句是SQL语句的重要组成部分,合理使用数据查询语句,可以极大的简化应用程序编制、快速的定位分析数据库系统的故障,查询语句是编程人员与数据库管理人员必不可少的工具,通过实验达到以下目的:(1)加深学生对查询语句基本概念的理解与掌握,最终达到灵活应用。(2)掌握SELECT 语句的基本语法。(3)掌握简单单表查询、连接查询、嵌套查询。(4)学会使用聚函数和进行分组查询。二、实验内容:1、单表查询:2、连接查询3、嵌套查询 三、实验环境 Windows xp系统 SQL Server2000 服务器四、程序源码与运行结果 1、单表查询

2、:设计查询语句完成对 *、distinct、like(%和_)、in 、not in 、between and、order by 、group by等的应用。(1)检索出学生信息表中所有女生的记录。Select * from student where sex=女(2)从选课成绩表中检索出所有学生的成绩,并去除重复值。select distinct grade from cs(3)从课程表中检索出全部数据的信息。select * from course where cname like 数据%(3)从学生信息表中检索出姓王的学生的信息。select * from student where s

3、name like 王_(4)从成绩表中找出成绩等于60分的学生的性别。select sex from student where sno in (select sno from cs where grade=60)(5)找出不在成绩表中的学生的所有信息。select * from student where sno not in (select sno from cs)(6)在成绩表中找出成绩从70到85分的所有信息。select * from cs where grade between 70 and 85(7)将学生表中的所有学生的年龄按升序排列。select * from studen

4、t order by age(8)检索出没门课程的平均分。select cno,avg(grade) from cs group by cno2、连接查询设计查询语句,分别用两种方式(where+连接条件和joinon)表示连接条件实现连接查询(1)找出成绩大于90分的姓名和他们所在的专业。(where+连接条件)select distinct sname,dept from student,cs where (grade90)(2)找出成绩大于85分的姓名和他们所在的专业。(joinon)select distinct sname,deptfrom student join cs on(st

5、udent.sno=cs.sno) where (grade85)3、嵌套查询具体要完成的任务如下:1. 查询全体学生的学号与姓名select sno,sname from student2. 查询全体学生的全部信息,并为学生表命名别名。select * from student W,course E ,cs B where W.sno=B.sno and E.cno=B.cno3. 查全体学生的出生年份,并为年份加上标题select 出生日期 from student4. 查询选修了课程的学生学号,要求消除重复行select sno from student where sno in(sel

6、ect sno from cs)5. 查询所有年龄在20岁以下的学生姓名及其年龄。select sname,age from student where age=20 and age=23) (第二种)7. 使用IN关键字查询信息系(IS)、数学系(MA)和计算机科学系(CS)的学生select * from student where sno in(select sno from student where dept=IS)select * from studentwhere sno in(select sno from student where dept=MA)select * from

7、 studentwhere sno in(select sno from student where dept=CS)8. 查询既不是信息系、数学系,也不是计算机科学系的学生的姓名和性别。select sname,sex from student where dept!=MAand dept!=CSand dept!=IS9. 查询所有姓刘学生的姓名、学号和性别。select sname,sno,sex from student where sname like 刘%10. 查询名字中第2个字为阳字的学生的姓名和学号。select sname,sno from student where sn

8、ame like _阳11. 查询DB_Design课程的课程号和学分(先在Course表中插入“DB_Design”课程信息)。select cname,score from course where cname=DB_Design12. 查询没有考试成绩的学生学号和课程号。select sno,cno from cs where grade is null13. 查询计算机系年龄在20岁以下的学生姓名。select sname from student where age=321、 查询有3门以上课程是90分以上的学生的学号及(90分以上的)课程数。select sno,count(cno

9、) from cs where grade=90group by sno having count(cno)=322、 查询全体学生与选课表的笛卡尔积。select * from student cross join course 23、 查询每个学生及其选修课程的情况。select distinct * from student cross join cs where student.sno=cs.sno24、 查询每个学生及其选修课程的情况(去掉重复属性)select a.sno,sname,sex,dept,age,o,cname,score,c.gradefrom student a,

10、course b,cs c where a.sno=c.sno and o=o25、 查询某门课程考试成绩相同的学生学号和课程信息select a.sno,o,ame,b.score from cs a,course bwhere o=o and (select count(*) from cs where cno=cno and grade=grade)=226、 查询每个学生的选修课程包括没有选修课程的学生(外连接)select * from student a,cs b where a.sno*=b.sno27、 查询每个学生的选修课程包括没有被学生选修的课程(外连接)select *

11、from student ,cs where student.sno =*cs.sno28、 查询每个学生的选修课程即包括没有被学生选修的课程又包括没有被学生选修的课程(全连接)select * from student full join cs on student.sno=cs.sno29、 查询选修2号课程且成绩在90分以上的所有学生的学号、姓名select sno,sname from studentwhere sno in(select sno from cs where grade=90and cno=C002)30、 查询每个学生的学号、姓名、选修的课程名及成绩select st

12、udent.sno,sname,cname,grade from student,course,cswhere (student.sno=cs.sno) and (o=o)31、 查询与“张三”在一个系学习的学生(IN)select * from studentwhere dept in(select dept from student where sname=张三)32、 查询选修了课程名为“信息系统”的学生学号和姓名。select sno,sname from studentwhere sno in (select sno from cs where cno in(select cno f

13、rom course where cname=信息系统)33、 查询与“张三”在同一个系学习的学生select * from studentwhere dept in (select dept from student where sname=张三)34、 查询选修了课程1或者选修了课程2的学生(要求消除重复组UNION)(select sno from cs where cno=C001 ) UNION(select sno from cs where cno=C002)35、 查询选修了课程1或者选修了课程2的学生(要求不消除重复组UNION ALL)(select sno from cs where cno=C001 ) UNION all(select sno from cs where cno=C002)五、实验总结 通过本次试验,掌握了使用SQL语句查询的技巧。

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1