數(shù)據(jù)庫(kù)實(shí)驗(yàn)8報(bào)告_第1頁(yè)
數(shù)據(jù)庫(kù)實(shí)驗(yàn)8報(bào)告_第2頁(yè)
數(shù)據(jù)庫(kù)實(shí)驗(yàn)8報(bào)告_第3頁(yè)
數(shù)據(jù)庫(kù)實(shí)驗(yàn)8報(bào)告_第4頁(yè)
數(shù)據(jù)庫(kù)實(shí)驗(yàn)8報(bào)告_第5頁(yè)
已閱讀5頁(yè),還剩11頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、數(shù)據(jù)庫(kù)原理及應(yīng)用實(shí)驗(yàn)報(bào)告實(shí)驗(yàn)名稱: 數(shù)據(jù)檢索(2)-多表查詢 學(xué) 院: 計(jì)算機(jī)學(xué)院 班 級(jí): 計(jì)算機(jī)應(yīng)用技術(shù)大專班 學(xué) 號(hào): 201113131121 姓 名: 黃錫杏 實(shí)驗(yàn)日期: 2013年4月19日 目錄一、實(shí)驗(yàn)準(zhǔn)備21、設(shè)備22、知識(shí)點(diǎn)2二、實(shí)驗(yàn)?zāi)康?三、實(shí)驗(yàn)內(nèi)容3(1).查詢所有班級(jí)的期末成績(jī)平均分,并按照平均分降序排序3(2).查詢教師基本信息和教授課程信息,其中包括未分配課程的教師信息5(3).查詢090501班級(jí)中選修了韓晉升老師講授的課程的學(xué)生的學(xué)號(hào)、姓名、課程名和期末成績(jī)6(4).查詢每門課程的課程號(hào)、課程名和選修該課程的學(xué)生人數(shù),并按所選人數(shù)升序排序7(5).查詢兩門及以上

2、課程的期末成績(jī)超過(guò)80分的學(xué)生的姓名及其平均成績(jī)8(6).查詢?nèi)雽W(xué)考試成績(jī)最高的學(xué)生的學(xué)號(hào)、姓名和入學(xué)成績(jī)9(7).查詢所有教授c05127號(hào)課程的教師信息9(8).查詢同時(shí)教授c05127號(hào)和c05109號(hào)課程的教師信息10(9).查詢至少選修了姓名為韓吟秋的學(xué)生所選課程中一門課的學(xué)生的學(xué)號(hào)和姓名10(10).查詢沒(méi)有被任何學(xué)生選修的課程編號(hào)、課程名和學(xué)分11(11).查詢“C語(yǔ)言”課程期末成績(jī)比“電子技術(shù)”課程期末成績(jī)高的所有學(xué)生的學(xué)號(hào)和姓名12(12).查詢所有班級(jí)期末平均成績(jī)的最高分,并將其賦值給變量,通過(guò)PRINT語(yǔ)句輸出13(13)實(shí)用游標(biāo)輸出學(xué)生姓名、選修課程名稱和期末考試成績(jī)1

3、4四、總結(jié)15一、實(shí)驗(yàn)準(zhǔn)備1、設(shè)備 PC機(jī)一臺(tái)、SQL Server2005(企業(yè)版)2、知識(shí)點(diǎn) 回顧教材主要知識(shí)點(diǎn),主要在教材的第六章 (1)、利用多表連接方式查詢數(shù)據(jù)(JOIN函數(shù)) (2)、利用子查詢方式查詢數(shù)據(jù)(嵌套查詢) (3)、利用游標(biāo)處理結(jié)果集的基本過(guò)程 (4)、上網(wǎng)搜索相關(guān)的只是來(lái)補(bǔ)充課本的缺陷(如JOIN函數(shù)的不同用法)二、實(shí)驗(yàn)?zāi)康?、重點(diǎn)掌握J(rèn)OINON語(yǔ)句的關(guān)系及應(yīng)用,并懂得與子句查詢的轉(zhuǎn)換;2、掌握連接查詢、子查詢、游標(biāo)、大對(duì)象類型數(shù)據(jù)的基本概念;3、掌握多表連接的各種方法,包括內(nèi)連接、外連接、交叉連接等;4、掌握子查詢的方法,包括相關(guān)子查詢和不相關(guān)子查詢5、掌握 游標(biāo)

4、處理結(jié)果集的基本過(guò)程三、實(shí)驗(yàn)內(nèi)容要根據(jù)提供的實(shí)驗(yàn)內(nèi)容資料,如實(shí)填寫實(shí)驗(yàn)的操作步驟步驟、操作語(yǔ)句、臨時(shí)或最終結(jié)果等,主要內(nèi)容見(jiàn)下;(1).查詢所有班級(jí)的期末成績(jī)平均分,并按照平均分降序排序代碼:use teachinggoselect classno,avg(final) from score inner join studenton (score.studentno=student.studentno)where final is not nullgroup by classnoorder by avg(final) desc結(jié)果: 對(duì)比 下面(2).查詢教師基本信息和教授課程信息,其中包括未

5、分配課程的教師信息代碼:use teachinggo select teacher.*,courseno,classnofrom teacher left join teach_classon(teacher.teacherno=teach_class.teacherno)結(jié)果:(3).查詢090501班級(jí)中選修了韓晉升老師講授的課程的學(xué)生的學(xué)號(hào)、姓名、課程名和期末成績(jī)代碼:use teachinggoselect student.studentno,sname,cname,finalfrom score join student on(score.studentno=student.stud

6、entno)join course on(score.courseno=course.courseno)join teach_class on(score.courseno=teach_class.courseno)join teacher on(teach_class.teacherno=teacher.teacherno)where tname='韓晉升' and student.classno='090501'結(jié)果:(4).查詢每門課程的課程號(hào)、課程名和選修該課程的學(xué)生人數(shù),并按所選人數(shù)升序排序代碼:use teachinggoselect course.

7、courseno,cname,count(*)from score join student on(score.studentno=student.studentno)join course on(score.courseno=course.courseno)group by course.courseno,cnameorder by count(*)結(jié)果:(5).查詢兩門及以上課程的期末成績(jī)超過(guò)80分的學(xué)生的姓名及其平均成績(jī)代碼:use teachinggoselect student.studentno,sname,avg(final)as avgeragefrom student inn

8、er join scoreon(student.studentno=score.studentno)where final is not null and final>=80group by student.studentno,snamehaving count(*)>=2結(jié)果:(6).查詢?nèi)雽W(xué)考試成績(jī)最高的學(xué)生的學(xué)號(hào)、姓名和入學(xué)成績(jī)代碼:use teachinggoselect studentno,sname,pointfrom studentwhere point=( select max(point) from student )結(jié)果:(7).查詢所有教授c05127號(hào)課程的

9、教師信息代碼:use teachinggo select *from teacherwhere teacherno in( select teacherno from teach_class where courseno='c05127' )結(jié)果:(8).查詢同時(shí)教授c05127號(hào)和c05109號(hào)課程的教師信息代碼:use teachinggoselect *from teacherwhere teacherno in( select a.teacherno from teach_class a inner join teach_class b on(a.teacherno=b

10、.teacherno) where a.courseno='c05127'and b.courseno='c05109')結(jié)果:(9).查詢至少選修了姓名為韓吟秋的學(xué)生所選課程中一門課的學(xué)生的學(xué)號(hào)和姓名代碼:use teaching goselect distinct student.studentno,snamefrom student join score on(student.studentno=score.studentno)where sname<>'韓吟秋' and courseno in(select courseno

11、from score join student on(score.studentno=student.studentno) where sname='韓吟秋')結(jié)果:(10).查詢沒(méi)有被任何學(xué)生選修的課程編號(hào)、課程名和學(xué)分代碼:use teachinggoselect courseno,cname,creditfrom coursewhere not exists(select *from scorewhere score.courseno=course.courseno)結(jié)果:(11).查詢“C語(yǔ)言”課程期末成績(jī)比“電子技術(shù)”課程期末成績(jī)高的所有學(xué)生的學(xué)號(hào)和姓名代碼:use

12、teachinggoselect student.studentno,snamefrom score sc1 join student on(sc1.studentno=student.studentno) join course c1 on(sc1.courseno=c1.courseno)where c1 ame='C語(yǔ)言'and exists(select * from score sc2 join course c2on(sc2.courseno=c2.courseno)where c2 ame='電子技術(shù)'and sc1.studentno=sc2.s

13、tudentno and sc1.final>sc2.final)結(jié)果:(12).查詢所有班級(jí)期末平均成績(jī)的最高分,并將其賦值給變量,通過(guò)PRINT語(yǔ)句輸出代碼:use teachinggodeclare max numeric(6,2)select max=max(平均分)from (select classno as 班級(jí)號(hào),avg(final) as 平均分 from score join studenton(score.studentno=student.studentno) join course on(course.courseno=score.courseno) where

14、 final is not null group by classno)tprint'所有班級(jí)期末平均成績(jī)的最高分:'+cast(max as varchar(6)結(jié)果:(13)實(shí)用游標(biāo)輸出學(xué)生姓名、選修課程名稱和期末考試成績(jī)代碼:use teaching godeclare sname nchar(8),cname nchar(10),final numeric(6,2)declare sc_cursor cursor for select sname,cname,final from score join student on(score.studentno=student

15、.studentno) join course on(score.courseno=course.courseno)open sc_cursorfetch next from sc_cursor into sname,cname,finalprint '學(xué)生姓名 課程名稱 期末成績(jī)'print '-'while fetch_status=0begin print sname+cname+cast(final as nchar(6) fetch next from sc_cursor into sname,cname,finalendclose sc_cursordeallocate sc_cursor結(jié)果:四、總結(jié)1、在這次實(shí)驗(yàn)之前,認(rèn)真查閱書(shū)本上相關(guān)知識(shí)點(diǎn)和代碼;2、通過(guò)這次實(shí)驗(yàn)基本掌握多表連接查詢方法、掌握IN 子查詢的嵌套

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論