华南农业大学数据库系统概念实验一报告三.docx

上传人:b****5 文档编号:7008924 上传时间:2023-01-16 格式:DOCX 页数:10 大小:326.48KB
下载 相关 举报
华南农业大学数据库系统概念实验一报告三.docx_第1页
第1页 / 共10页
华南农业大学数据库系统概念实验一报告三.docx_第2页
第2页 / 共10页
华南农业大学数据库系统概念实验一报告三.docx_第3页
第3页 / 共10页
华南农业大学数据库系统概念实验一报告三.docx_第4页
第4页 / 共10页
华南农业大学数据库系统概念实验一报告三.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

华南农业大学数据库系统概念实验一报告三.docx

《华南农业大学数据库系统概念实验一报告三.docx》由会员分享,可在线阅读,更多相关《华南农业大学数据库系统概念实验一报告三.docx(10页珍藏版)》请在冰豆网上搜索。

华南农业大学数据库系统概念实验一报告三.docx

华南农业大学数据库系统概念实验一报告三

《数据库系统》实验报告三

学号

姓名

实验时间

2014-11-26

实验名称

数据查询

实验学时

4

准备材料

1.SQLPlus命令手册

2.Oracle数据字典

扩展实验

1.利用企业管理器的图形界面构造查询语句,并察看查询结果

2.利用企业管理器完成视图、索引的创建与使用。

3.利用DBMS进行对第三章习题所设计SQL语句的检查

(此部分内容不要求在实验室完成,不用写入实验报告。

实验环境

Oracle9i(及以上版本)服务器

SQLPlus/SQLPlusworksheet客户端

实验目的

1.掌握使用SQL语句进行数据查询的方法

2.掌握视图的创建与使用方法

3.观察索引的使用效果

实验内容及步骤

1.使用University数据库的数据库结构和数据(smallRelations即可),完成下列查询:

(1)FindthenamesofcoursesinComputersciencedepartmentwhichhave3credits

SELECTtitle

FROMcourse

WHEREdept_name='Comp.Sci.'ANDcredits=3

(2)ForthestudentwithID12345(oranyothervalue),showallcourse_idandtitleofallcoursesregisteredforbythestudent.

SELECTcourse_id,title

FROMtakesNATURALJOINcourse

WHEREid=12345

4.Asabove,butshowthetotalnumberofcreditsforsuchcourses(takenbythatstudent).Don'tdisplaythetot_credsvaluefromthestudenttable,youshoulduseSQLaggregationoncoursestakenbythestudent.

SELECTid,SUM(credits)

FROMtakesNATURALJOINstudentNATURALJOINcourse

WHEREid=12345

GROUPBYid;

(3)Asabove,butdisplaythetotalcreditsforeachofthestudents,alongwiththeIDofthestudent;don'tbotheraboutthenameofthestudent.(Don'tbotheraboutstudentswhohavenotregisteredforanycourse,theycanbeomitted)

SELECTid,SUM(credits)

FROMtakesNATURALJOINstudentNATURALJOINcourse

GROUPBYid

(4)FindthenamesofallstudentswhohavetakenanyComp.Sci.courseever(thereshouldbenoduplicatenames)

SELECTDISTINCTid,NAME

FROMtakesNATURALJOINstudent

WHEREcourse_idIN(SELECTcourse_id

FROMcourse

WHEREdept_name='Comp.Sci.')

(5)DisplaytheIDsofallinstructorswhohavenevertaughtacourse(Notesad1)Oracleusesthekeywordminusinplaceofexcept;

(2)interpret"taught"as"taughtorisscheduledtoteach")

SELECTid

FROMinstructor

WHEREidNOTIN(SELECTDISTINCTid

FROMteaches

(6)Asabove,butdisplaythenamesoftheinstructorsalso,notjusttheIDs.

SELECTid,NAME

FROMinstructor

WHEREidNOTIN(SELECTDISTINCTid

FROMteaches

(7)Findthemaximumandminimumenrollmentacrossallsections,consideringonlysectionsthathadsomeenrollment,don'tworryaboutthosethathadnostudentstakingthatsection

SELECTmax(enrollment),min(enrollment)

from(

SELECTsec_id,semester,year,

COUNT(DISTINCTid)asenrollment

FROMtakes

GROUPBYsec_id,semester,YEAR);

(8)AsininQ1,butnowalsoincludesectionswithnostudentstakingthem;theenrollmentforsuchsectionsshouldbetreatedas0.Dothisintwodifferentways(andcreaterequiredatafortesting)1).Usingascalarsubquery2).Usingaggregationonaleftouterjoin(usetheSQLnaturalleftouterjoinsyntax)

SELECTDISTINCTsec_id,semester,YEAR,IFNULL(`count`,0)

FROMsectionLEFTOUTERJOIN

(SELECTsec_id,semester,YEAR,COUNT(DISTINCTid,sec_id,semester,YEAR)AS'count'

FROMtakes

GROUPBYsec_id,semester,YEAR)ASTUSING(sec_id,semester,YEAR)

(9)Findallcourseswhoseidentifierstartswiththestring"CS-1"

SELECT*

FROMcourse

WHEREcourse_idLIKE'CS-1%'

(10)Findinstructorswhohavetaughtalltheabovecourses1).Usingthe"notexists...except..."structure2).Usingmatchingofcountswhichwecoveredinclass(don'tforgetthedistinctclause!

selectdistinctID,namefromteachesnaturaljoininstructor

wherenotexists((selectcourse_idfromcourse)

except(selectcourse_idfromcoursewherecourse_idlike'CS-1%'));

2.TheuniversityrulesallowanFgradetobeoverriddenbyanypassgrade(A,B,C,D).Now,createaviewthatlistsinformationaboutallfailgradesthathavenotbeenoverridden(theviewshouldcontainallattributesfromthetakesrelation).

CREATEVIEWFAS

SELECT*

FROMtakes

WHEREgrade='F'

 

3.Findallstudentswhohave2ormorenon-overriddenFgradesasperthetakesrelation,andlistthemalongwiththeF

selectname,'F'asfinal_grade

fromFnaturaljoinstudent

groupbyname

havingcount(grade)>=2;

选择数量〉=1时有一个结果

出现问题

 

解决方案

(列出遇到的问题及其解决方法)

 

 

精品文档考试教学资料施工组织设计方案

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 初中教育 > 语文

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

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