资源描述:
《数据库系统概念第六版课后习题部分答案3s》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、CHAPTER3IntroductiontoSQLExercises3.1WritethefollowingqueriesinSQL,usingtheuniversityschema.(Wesug-gestyouactuallyrunthesequeriesonadatabase,usingthesampledatathatweprovideontheWebsiteofthebook,db-book.com.Instructionsforsettingupadatabase,andloadingsampledata,areprovidedontheaboveWebsite.)a.Findth
2、etitlesofcoursesintheComp.Sci.departmentthathave3credits.b.FindtheIDsofallstudentswhoweretaughtbyaninstructornamedEinstein;makesuretherearenoduplicatesintheresult.c.Findthehighestsalaryofanyinstructor.d.Findallinstructorsearningthehighestsalary(theremaybemorethanonewiththesamesalary).e.Findtheenrol
3、lmentofeachsectionthatwasofferedinAutumn2009.f.Findthemaximumenrollment,acrossallsections,inAutumn2009.g.FindthesectionsthathadthemaximumenrollmentinAutumn2009.Answer:a.FindthetitlesofcoursesintheComp.Sci.departmentthathave3credits.selecttitlefromcoursewheredeptname=’Comp.Sci.’andcredits=356Chapter
4、3IntroductiontoSQLb.FindtheIDsofallstudentswhoweretaughtbyaninstructornamedEinstein;makesuretherearenoduplicatesintheresult.Thisquerycanbeansweredinseveraldifferentways.Onewayisasfollows.selectdistinctstudent.IDfrom(studentjointakesusing(ID))join(instructorjointeachesusing(ID))using(courseid,secid,
5、semester,year)whereinstructor.name=’Einstein’Asanalternativetothjoin..usingsyntaxabovethequerycanbewrittenbyenumeratingrelationsinthefromclause,andaddingthecorrespondingjoinpredicatesonID,courseid,sectionid,semester,andyeartothewhereclause.Notethatusingnaturaljoininplaceofjoin..usingwouldresultineq
6、uatingstudentIDwithinstructorID,whichisincorrect.c.Findthehighestsalaryofanyinstructor.selectmax(salary)frominstructord.Findallinstructorsearningthehighestsalary(theremaybemorethanonewiththesamesalary).selectID,namefrominstructorwheresalary=(selectmax(salary)frominstructor)e.Findtheenrollmentofeach
7、sectionthatwasofferedinAutumn2009.Onewayofwritingthequeryisasfollows.selectcourseid,secid,count(ID)fromsectionnaturaljointakeswheresemester=’Autumn’andyear=2009groupbycourseid,secidNotethatifasectiondoesnot