SQL數(shù)據(jù)查詢策略可編輯_第1頁
SQL數(shù)據(jù)查詢策略可編輯_第2頁
SQL數(shù)據(jù)查詢策略可編輯_第3頁
SQL數(shù)據(jù)查詢策略可編輯_第4頁
SQL數(shù)據(jù)查詢策略可編輯_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、集團文件版本號:(M928-T898-M248-WU2669-I2896-DQ586-M1988)實驗名稱:SQL數(shù)據(jù)查詢一、實驗?zāi)康模簲?shù)據(jù)查詢語句是SQL語句的重要組成部分,合理使用數(shù)據(jù)查詢語句,可以極大的 簡化應(yīng)用程丿宇編制、快速的定位分析數(shù)據(jù)庫系統(tǒng)的故障,查詢語句是編程人員與數(shù)據(jù) 庫管理人員必不可少的工具,通過實驗達到以下目的:(1)加深學(xué)生對查詢語句基本概念的理解與學(xué)握,最終達到靈活應(yīng)用。(2)掌握SELECT語句的基本語法。(3)常握簡單單表查詢、連接查詢、嵌套查詢。(4)學(xué)會使用聚函數(shù)和進行分組查詢。二、實驗內(nèi)容:1、單表查詢:2、連接查詢3、嵌套查詢?nèi)嶒灜h(huán)境Windows x

2、p 系統(tǒng) SQL Server2000 服務(wù)器四、程序源碼與運行結(jié)果1、單表查詢:設(shè)計查詢語句完成對 *、distinct、like (%和_)、in、not in、betweenand、order by、group by 等的應(yīng)用。(1)檢索出學(xué)生信息表中所有女生的記錄。Select * from student where sex二女(2)從選課成績表中檢索出所有學(xué)生的成績,并去除重復(fù)值。select distinct grade from cs(3)從課程表中檢索出全部數(shù)據(jù)的信息。select * from course where cname like 數(shù)據(jù)(3)從學(xué)生信息表中檢索出姓

3、王的學(xué)生的信息。select * from student where sname like 王_(4)從成績表中找出成績等于60分的學(xué)生的性別。6. 查詢年齡在2023歲的學(xué)生信息(要求至少使用兩種方式完成查詢)select * from student where age between 20 and 23 (第一種) select * from student where (age=20 and age=23) (第二種)7. 使用IN關(guān)鍵字查詢信息系(IS)、數(shù)學(xué)系(MA)和計算機科學(xué)系(CS)的 學(xué)生select * from studentwhere sno in (select

4、sno from student where dept二IS)select * from studentwhere sno in (select sno from student where dept二MA)select * from studentwhere sno in (select sno from student where dept二CS)8. 查詢既不是信息系、數(shù)學(xué)系,也不是計算機科學(xué)系的學(xué)生的姓名和性別。 select sname, sex from studentwhere dept !二MAand dept!二CSand dept!二TS9. 查詢所有姓劉學(xué)生的姓名、學(xué)號和

5、性別。select sname, sno, sex from student where sname like ,文10. 查詢名字中第2個字為邙日字的學(xué)生的姓名和學(xué)號。select sname, sno from student where sname like 陽11. 查詢DB_Design課程的課程號和學(xué)分(先在Course表中插入DB_Design” 課程信息)。select cname, score from course where cname二DB_Design12. 查詢沒有考試成績的學(xué)生學(xué)號和課程號。13. 查詢計算機系年齡在20歲以下的學(xué)生姓名。select sname

6、from student where age=321、查詢有3門以上課程是90分以上的學(xué)生的學(xué)號及(90分以上的)課程數(shù)。select sno,count (eno) from cs where grade=90group by sno having count (eno)=322、查詢?nèi)w學(xué)生與選課表的笛卡爾積。23、查詢每個學(xué)生及其選修課程的情況。select distinct * from student cross join cs where student snores sno24、查詢每個學(xué)生及其選修課程的情況(去掉重復(fù)屬性)select a. sno, sname, sex, d

7、ept, age, b eno, cname, score, c. gradefrom student a, course b, cs c where a.sno二c sno and b cno=c eno25、查詢某門課程考試成績相同的學(xué)生學(xué)號和課程信息select a. sno, b eno, b cname, b score from cs a, course bwhere a. cno=beno and (select count(*) from cs where eno二eno and grade=grade)二226、查詢每個學(xué)生的選修課程包括沒有選修課程的學(xué)生(外連接)selec

8、t * from student a, cs b where a.sno*二b sno27、查詢每個學(xué)生的選修課程包括沒有被學(xué)生選修的課程(外連接)select * from student ,cs where student sno =*cs sno28、查詢每個學(xué)生的選修課程即包括沒有被學(xué)生選修的課程又包括沒有被學(xué)生選修的 課程(全連接)select * from student full join cs on student sno二cs sno29、查詢選修2號課程且成績在90分以上的所有學(xué)生的學(xué)號、姓名select sno, sname from studentwhere sno i

9、n(select sno from cs where grade二90and cno=,C002,)30、查詢每個學(xué)生的學(xué)號、姓名、選修的課程名及成績select student. sno, sname, cname, grade from student, course,cswhere (student sno二cs sno) and (course cno=cs eno)31、查詢與“張三”在一個系學(xué)習(xí)的學(xué)生(IN)where dept in(select dept from student where sname二弓長三)32、查詢選修了課程名為“信息系統(tǒng)”的學(xué)生學(xué)號和姓名。select sno, sname from studentwhere sno in (select sno from cs where eno in(select eno from course wherecname二信息系統(tǒng))33、查詢與“張三”在同一個系學(xué)習(xí)的學(xué)生select * from studentwhere dept in (select dept from student where sname張三)34、查詢選修了課程1或者選修了課程2的學(xué)生(要求消除重復(fù)組UNION)(selectsnofromcswherecno=,C001,)UNION(selectsnofro

溫馨提示

  • 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)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論