




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、数据库系统实验报告三学号姓名实验时间2014-11-26实验名称数据查询实验学时4准备材料1. SQL Plus命令手册2. Oracle数据字典扩展实验1. 利用企业管理器的图形界面构造查询语句,并察看查询结果2. 利用企业管理器完成视图、索引的创建与使用。3. 利用DBMS进行对第三章习题所设计SQL语句的检查 (此部分内容不要求在实验室完成,不用写入实验报告。)实验环境Oracle 9i(及以上版本)服务器SQL Plus/ SQL Plus work sheet客户端实验目的1掌握使用SQL语句进行数据查询的方法2. 掌握视图的创建与使用方法3. 观察索引的使用效果实验内容及步骤1.
2、使用University数据库的数据库结构和数据(smallRelations即可),完成下列查询:(1) Find the names of courses in Computer science department which have 3 creditsSELECT titleFROM courseWHERE dept_name = Comp. Sci. AND credits = 3(2) For the student with ID 12345 (or any other value), show all course_id and title of all courses re
3、gistered for by the student. SELECT course_id,titleFROM takes NATURAL JOIN courseWHERE id = 123454. As above, but show the total number of credits for such courses (taken by that student). Dont display the tot_creds value from the student table, you should use SQL aggregation on courses taken by the
4、 student. SELECT id,SUM(credits)FROM takes NATURAL JOIN student NATURAL JOIN courseWHERE id = 12345GROUP BY id;(3) As above, but display the total credits for each of the students, along with the ID of the student; dont bother about the name of the student. (Dont bother about students who have not r
5、egistered for any course, they can be omitted) SELECT id,SUM(credits)FROM takes NATURAL JOIN student NATURAL JOIN courseGROUP BY id(4) Find the names of all students who have taken any Comp. Sci. course ever (there should be no duplicate names) SELECT DISTINCT id,NAMEFROM takes NATURAL JOIN studentW
6、HERE course_id IN (SELECT course_id FROM course WHERE dept_name=Comp. Sci.)(5) Display the IDs of all instructors who have never taught a course (Notesad1) Oracle uses the keyword minus in place of except; (2) interpret taught as taught or is scheduled to teach)SELECT idFROM instructorWHERE id NOT I
7、N (SELECT DISTINCT id FROM teaches ) (6) As above, but display the names of the instructors also, not just the IDs.SELECT id,NAMEFROM instructorWHERE id NOT IN (SELECT DISTINCT id FROM teaches )(7) Find the maximum and minimum enrollment across all sections, considering only sections that had some e
8、nrollment, dont worry about those that had no students taking that sectionSELECT max(enrollment),min(enrollment)from(SELECT sec_id,semester,year,COUNT(DISTINCT id) as enrollmentFROM takesGROUP BY sec_id,semester,YEAR); (8) As in in Q1, but now also include sections with no students taking them; the
9、enrollment for such sections should be treated as 0. Do this in two different ways (and create require data for testing) 1). Using a scalar subquery 2). Using aggregation on a left outer join (use the SQL natural left outer join syntax)SELECT DISTINCT sec_id,semester,YEAR,IFNULL(count,0)FROM section
10、 LEFT OUTER JOIN(SELECT sec_id,semester,YEAR,COUNT(DISTINCT id,sec_id,semester,YEAR) AS countFROM takesGROUP BY sec_id,semester,YEAR) AS T USING (sec_id,semester,YEAR)(9) Find all courses whose identifier starts with the string CS-1 SELECT *FROM courseWHERE course_id LIKE CS-1%(10) Find instructors
11、who have taught all the above courses 1). Using the not exists . except . structure 2). Using matching of counts which we covered in class (dont forget the distinct clause!) select distinct ID,name from teaches natural join instructor where not exists (select course_id from course)except (select cou
12、rse_id from course where course_id like CS-1%);2. The university rules allow an F grade to be overridden by any pass grade (A, B, C, D). Now, create a view that lists information about all fail grades that have not been overridden (the view should contain all attributes from the takes relation).CREATE VIEW F AS SELECT * FROM takes WHERE grade = F3. Find all students who have 2 or more non-overridden F grades as
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 玉米原材料采购合同范本
- 村委建设补偿协议书范本
- 禁止学生喝酒安全协议书
- 浦东同城厂房出租协议书
- 材料商玻璃采购合同范本
- 自建房套间出售合同范本
- 防晒服定制采购合同范本
- 注册人员聘用协议书范本
- 空压机节能方案合同范本
- 股东协议书与代持协议书
- 龋齿护理健康教育
- 研学旅行指导师笔试试题及答案
- 人工智能技术合同
- 2025年人教版八年级物理下学期期末复习:力、运动和力、压强、浮力(考点清单)学生版+解析
- 2025至2030中国矿用排水泵行业深度研究及发展前景投资评估分析
- 变形铝及铝合金圆铸锭国家标准
- PCN变更申请单
- 质量信得过班组获奖材料
- 常用硒鼓通用表
- 鹤山饮食文化
- 门诊注射室护理安全问题与防范措施分析
评论
0/150
提交评论