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.
2、观察索引的使用效果实验内容及步骤1. 使用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 titl
3、e of all courses registered 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 c
4、ourses taken by the 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 stud
5、ents who have not registered 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 NA
6、TURAL JOIN studentWHERE 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 instr
7、uctorWHERE id NOT IN (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 secti
8、ons that had some enrollment, 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 student
9、s taking them; the 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(c
10、ount,0)FROM section 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
11、) Find instructors 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
12、)except (select course_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 t
13、akes relation).CREATE VIEW F AS SELECT * FROM takes WHERE grade = F3. Find all students who have 2 or more non-overridden F grades as per the takes relation, and list them along with the Fselect name,Fas final_gradefrom F natural join studentgroup by namehaving count(grade)=2;选择数量=1时有一个结果出现问题解决方案(列出遇到的问题及其解决方法)精品文档考试教学资料施工组织设计方案
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1