简单SELECT语句(精选).docxVIP

  • 7
  • 0
  • 约2.13千字
  • 约 3页
  • 2021-01-15 发布于贵州
  • 举报
淮海工学院计算机工程学院 实 验 报 告 书 题目:简单 SELECT语句 题 目: 简单 SELECT语句 评语: 成绩: 指导教师: 批阅时间: 年 月 日 班 级: 计算机 学 号: 姓 名: - 4 -《数据库原理及应用》实验报告 - 4 - 《数据库原理及应用》实验报告 实验报告要求 目的与要求 SQL 语言的嵌套查询语句的。 掌握数据操纵的两种方法, 熟悉使用 UPDATE/INSERT/DELETE语句进行表操作; 能将这些更新操作应用于实际操作中去 。 实验内容 ( 1) SQL 语言的嵌套查询 ;(参考指导书实验四) ( 2) 使用 UPDATE/INSERT/DELETE语句进行表操作 ( 可以参考教材的例子 ) 实验步骤 所有的查询全部用 Transact-SQL 语句实现 简单查询操作 此部分查询包括投影、选择条件表达、数据排序、使用临时表等。对 EDUC数据库实现以下查询: ① 求计算机系的学生学号和姓名; select sno , sname from student where spno = 计算机 ② 求选修了课程的学生学号; select sno from student_course ② 求选修 C1 课程的学生学号和成绩, 并要求对查询结果按成绩的降序排列, 如果成绩相同则按学号的升序排列; select sno , score from student_course where cno =1 order by score desc , sno asc ; ③ 求选修课程 C1 且成绩在 80- 90 之间的学生学号和成绩,并将成绩乘以系数 0.75 输出; select sno , 0.75 * score from student_course where cno =2 and ( score between 80 and 90 ); ④ 求计算机系和数学系的姓张的学生的信息; select * from student where sname like 张% and ( spno = 计算机 or spno = 数 学 ) ⑤ 求缺少了成绩的学生的学号和课程号。 select sno , cno from student_course where score is null ⑥ 将 2000 以后的成绩大于 90 分的学生成绩存入永久成绩表; 将 2000 年以前的成绩存入临时成绩表中。 select * into forver ;#forver from student_course where [year]2000-1-1 and score90 ;[year]2000-1-1 连接查询操作 对 EDUC数据库实现以下查询: ① 查询每个学生的情况以及他(她)所选修的课程; 方法一: select student .*, student_course .* from student , student_course where student . sno = student_course . sno 方法二:(自然连接) select student.*,student_course.cno, student_course.score from student, student_course where student . sno = student_course . sno 方法三:(外连接) selectstudent select student .*, student_course . cno , student_course from student left join student_course on ( student . sno =student_course . sno ); ② 求学生的学号、姓名、选修的课程名及成绩; select student.sno,sname,cname,score from student,course,student_course where student.sno= student_course.sno and student_course.cno=course.cno ③ 求选修 C1 课程且成绩在 90 分以上的学生学号、姓名及成绩; select student . sno , sname , score from student , student_course where cno =1 and student_course . score 90 and student . sno =student_course . sno ④ 查询每一门课的间接先行课。select co

文档评论(0)

1亿VIP精品文档

相关文档