实验数据查询及t-sql语言基础

上传人:艾力 文档编号:36406693 上传时间:2018-03-28 格式:DOC 页数:3 大小:38KB
返回 下载 相关 举报
实验数据查询及t-sql语言基础_第1页
第1页 / 共3页
实验数据查询及t-sql语言基础_第2页
第2页 / 共3页
实验数据查询及t-sql语言基础_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《实验数据查询及t-sql语言基础》由会员分享,可在线阅读,更多相关《实验数据查询及t-sql语言基础(3页珍藏版)》请在金锄头文库上搜索。

1、实验:数据查询及实验:数据查询及 T-sqlT-sql 语言基础语言基础一、实验目的一、实验目的1、学会使用 selcet 等 SQL 语句进行数据查询;二、实验内容二、实验内容1、首先将 S-C 数据库附加到 sql server 2000 的企业管理器中。 2、查询选修 c002 课程的学生的姓名和所在系。Sql 语句: select sname,sdept from student s,sc where s.sno=sc.sno and cno=c002结果: 李勇 计算机系 刘晨 计算机系 3、查询成绩 80 分以上的学生的姓名、课程号和成绩,并按成绩降序排列结果Sql 语句: sel

2、ect sname,cno,grade from student s join sc on s.sno=sc.sno where grade80 order by grade desc结果: 李勇 c001 96 刘晨 c001 92 刘晨 c002 90 吴宾 c004 85 刘晨 c004 84 李勇 c003 84 李勇 c005 82 4、查询哪些课程没有学生选修,要求列出课程号和课程名 Sql 语句: select o,cname from course c left join sc on o=o where o is null结果: c006 数据库技术 c008 计算机网络 5、

3、查询计算机系哪些学生没有选课,列出学生姓名Sql 语句: select sname from student s left join sc on s.sno=sc.sno where sc.sno is null and sdept=计算机系结果: 李敏 张小红 6、查询与“刘晨”在同一个系学习的学生的姓名。要求用两种方式查询提示:可以使用多表查询,还可以使用子查询。Sql 语句 1: select s1.sname from student s1 join student s2 on s1.sdept=s2.sdept where s1.sname!=刘晨 and s2.sname=刘晨Sq

4、l 语句 2: select sname from student where sdept=(select sdept from student where sname=刘晨)and sname!=刘晨结果: 李勇 李敏 张小红 7、查询成绩大于 90 分的学生的学号、姓名。要求用两种方式查询提示:可以使用多表查询,还可以使用子查询。Sql 语句 1: select sno, sname from student where grade90Sql 语句 2: select sno, sname from student where sno in(select sno from sc where

5、 grade90)结果: 0611101 李勇 0611102 刘晨 8、查询计算机系考试成绩最高的学生的姓名。要求用两种方式查询提示:可以使用多表查询,还可以使用子查询。Sql 语句 1: select sname from student s join sc on s.sno=sc.sno where sdept=计算机系 and grade=(select max(grade) from sc join student s on s.sno=sc.sno where sdept=计算机系)结果: 李勇 9、查询选修 c002 课程的学生姓名。 (用 exists) Sql 语句 1: s

6、elect sname from student where exists (select * from sc where sc.sno=student.sno and cno=c002)结果: 李勇 刘晨 10、查询没有选修 c001 课程的学生姓名和所在系。 Sql 语句 1: select sname from student where not exists (select * from sc where sc.sno=student.sno and cno=c001)结果: 李敏 张小红 张立 王大力 张姗姗 11、查询计算机系没有选修 vb 程序设计课程的学生的姓名和性别。 Sql

7、 语句 1: select sname from student where not exists (select * from sc,course where o=o and sno=student.sno and cname=vb 程序设计) and sdept=计算机系 Sql 语句 2: select sname from student where sno not in (select sno from sc,course where o=o and cname=vb 程序设计) and sdept=计算机系结果: 刘晨 李敏 张小红 12、在 sc 表中查询 C001 课程的考试情况,列出学号和成绩,同时对成绩做如下处理: 当成绩大于等于 90 分时,在结果中显示优; 当成绩在 8089 分时,在结果中显示良; 当成绩在 7079 分时,在结果中显示中; 当成绩在 6069 分时,在结果中显示及格; 当成绩小于 60 分时,在结果中显示不及格。

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号