管理SQL Server 數(shù)據(jù)庫 實驗5.doc_第1頁
管理SQL Server 數(shù)據(jù)庫 實驗5.doc_第2頁
管理SQL Server 數(shù)據(jù)庫 實驗5.doc_第3頁
管理SQL Server 數(shù)據(jù)庫 實驗5.doc_第4頁
全文預(yù)覽已結(jié)束

下載本文檔

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

文檔簡介

實驗五:數(shù)據(jù)庫綜合查詢一、實驗?zāi)康?. 掌握SELECT語句的基本語法和查詢條件表示方法;2. 掌握查詢條件種類和表示方法;3. 掌握連接查詢的表示及使用;4. 掌握嵌套查詢的表示及使用;5. 了解集合查詢的表示及使用。二、實驗環(huán)境已安裝SQL Server企業(yè)版的計算機(120臺);具有局域網(wǎng)環(huán)境,有固定IP;三、實驗學(xué)時2學(xué)時四、實驗要求1. 了解SELECT語句的基本語法格式和執(zhí)行方法;2. 了解連接查詢的表示及使用;3. 了解嵌套查詢的表示及使用;4. 了解集合查詢的表示及使用;5. 完成實驗報告;五、實驗內(nèi)容及步驟1.利用Transact-SQL嵌套語句實現(xiàn)下列數(shù)據(jù)查詢操作。(選課表2) 1) 查詢選修了計算機體系結(jié)構(gòu)的學(xué)生的基本信息。select * from student,course where ame=(select cname from course where cname=計算機體系結(jié)構(gòu)) 2) 查詢年齡比李勇小的學(xué)生的學(xué)號和成績。 select sc.snum,score from sc,student where sage (select sage=min(sage) from student where dnum=d1 )and dnum!=d1 4) 查詢其他系中比系編號為D3的學(xué)生年齡都大的學(xué)生的姓名。select sname from student where sage(select sage=max(sage) from student where dnum=d3 )and dnum!=d35) 查詢C1課程的成績高于70的學(xué)生姓名。select distinct sname from student,sc where score70 and cnum=c1and student.snum=sc.snum6) 查詢C1課程的成績不高于70的學(xué)生姓名。 select distinct sname from student,sc where score=2)10)查詢開設(shè)的課程和選修該課程的學(xué)生的總成績、平均成績、最高成績和最低成績。select cname,sum=sum(score),avg=avg(score),max=max(score),min=min(score) from sc,course group by cname(二)、以數(shù)據(jù)庫原理實驗4數(shù)據(jù)為基礎(chǔ),請使用T-SQL 語句實現(xiàn)進行以下操作:(student1)1. 查詢以DB_開頭,且倒數(shù)第3個字符為s的課程的詳細情況; select * from course where cname like db_%s_2. 查詢名字中第2個字為陽的學(xué)生姓名和學(xué)號及選修的課程號、課程名; select sname,student.sno,o,cname from student,sc,course where sname like _陽% and student.sno=sc.sno and o=o3. 列出選修了數(shù)學(xué)或者大學(xué)英語的學(xué)生學(xué)號、姓名、所在院系、選修課程號及成績; select student.sno,sname,sdept,o,cname from student,course where cname=數(shù)學(xué) or cname=大學(xué)英語4. 查詢?nèi)鄙俪煽兊乃袑W(xué)生的詳細情況; select * from student,sc where sc.grade is null and sc.sno=student.sno5. 查詢與張力(假設(shè)姓名唯一)年齡不同的所有學(xué)生的信息; select * from student where sage!=(select sage from student where sname=張力)6. 查詢所選課程的平均成績大于張力的平均成績的學(xué)生學(xué)號、姓名及平均成績; select student.sno,sname,平均成績=avg(grade) from student,sc where sc.sno=student.sno group by student.sno,sname having avg(grade)(select avg(grade) from sc where sno=(select sno from student where sname=張力)7. 按照“學(xué)號,姓名,所在院系,已修學(xué)分”的順序列出學(xué)生學(xué)分的獲得情況。其中已修學(xué)分為考試已經(jīng)及格的課程學(xué)分之和; select student.sno,sname,sdept,已修學(xué)分=sum(ccredit) from student,course,sc where o=o and sc.sno=student.sno and grade=60 group by student.sno,sname,sdept8. 列出只選修一門課程的學(xué)生的學(xué)號、姓名、院系及成績; select student.sno,sname,sdept,grade from student,sc where sc.sno=student.sno and student.sno in (select sno from sc group by sno having count(*)=1) 9. 查詢選修“數(shù)據(jù)庫”或“數(shù)據(jù)結(jié)構(gòu)”課程的學(xué)生的基本信息; select * from student where sno in (select sno from sc where cno in (select cno from course where cname=數(shù)據(jù)庫 or cname=數(shù)據(jù)結(jié)構(gòu))10. 列出所有課程被選修的詳細情況,包括課程號、課程名、學(xué)號、姓名及成績; select distinct o,ame,student.sno,sname,grade from course,sc,student where student.sno=sc.sno and o=o 11. 查詢只被一名學(xué)生選修的課程的課程號、課程名; select cno,cname from course where cno in (select cno from sc group by cno having count (cno)=1)12. 檢索所學(xué)課程包含學(xué)生張向東所學(xué)課程的學(xué)生學(xué)號、姓名; select distinct student.sno,sname from student,sc where sc.sno=student.sno and cno in (select cno from sc where sno in(select sno from student where sname=張向東)13. 檢索所學(xué)課程包含學(xué)生張向東所學(xué)全部課程的學(xué)生學(xué)號、姓名; select distinct student.sno,sname from student,sc where sc.sno=student.sno and cno in (select cno from sc where sno in(select sno from student where sname=張向東) and sname != 張向東 group by sc.sno,student.sno,sname having count(cno) =(select count(cno) from sc where sno=(select sno from student where sname=張向東)14. 使用嵌套查詢列出選修了“數(shù)據(jù)結(jié)構(gòu)”課程的學(xué)生學(xué)號和姓名; select sno,sname from student where sno in (select sno from sc where cno in (select cno from course where cname=數(shù)據(jù)結(jié)構(gòu))15. 使用嵌套查詢查詢其它系中年齡小于CS系的某個學(xué)生的學(xué)生姓名、年齡和院系;select sname,sage,sdept from student where sage (select max(sage) from student where sdept=cs) and sdept !=cs16. 使用ANY、ALL 查詢,列出其他院系中比CS系所有學(xué)生年齡小的學(xué)生; select sname,sage from student where sage any (select min(sage) from student where sdept=cs) and sdept !=csselect sname,sage from student where sage all (select sage from student where sdept=cs) and sdept !=cs17. 分別使用連接查詢和嵌套查詢,列出與張力在一個院系的學(xué)生的信息; 連接查詢: select * from student x,student y where x.sdept=y.sdept and x.sname=張力 嵌套查詢: select * from student where sdept in (select sdept from student where sname=張力)18. 使用集合查詢列出CS系的學(xué)生以及性別為女的學(xué)生名單; select sname from student where sdept=cs union select sname from student where ssex=女19. 使用集合查詢列出CS系的學(xué)生與年齡不大于19歲的學(xué)生的交集、差集; 交集:select * from student where sdept=cs intersect select * from stuednt where sgae

溫馨提示

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

評論

0/150

提交評論