



下載本文檔
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、不相關(guān)子查詢返回一個(gè)值(帶有比較運(yùn)算符的子查詢)例:查詢與“劉晨”在同一個(gè)系學(xué)習(xí)的學(xué)生。-子查詢實(shí)現(xiàn)(用=的前提是子查詢返回一個(gè)值,即單行單列,學(xué)生劉晨姓名在學(xué)生表中沒有重復(fù)值)select * from student where sdept =(select sdept from student where sname=劉晨 ); 例:查詢選修成績(jī)大于08001 號(hào)學(xué)生的平均成績(jī)的學(xué)生選課信息select *from sc where grade(select avg(grade) from sc where sno=08001); 例:查詢年齡大于所有學(xué)生平均年齡的學(xué)生信息select
2、* from student where sage(select avg(sage) from student); 例:查詢學(xué)校最小年齡的學(xué)生信息select * from student where sage=(select min(sage) from student); 例:查詢年齡處于李莉和趙海間的學(xué)生信息select * from student where sage between(select sage from student where sname=李莉 ) and (select sage from student where sname= 趙海 ); 或select *
3、from student where sage =(select sage from student where sname=李莉 ) and sage =(select sage from student where sname= 趙海 ); 返回一組值(帶有in 謂詞的子查詢、帶有any(some )或 all 謂詞的子查詢)帶有 in 謂詞的子查詢例:選修 002 號(hào)課程的學(xué)生姓名-子查詢select sname from student where sno in(select sno from sc where cno=002); -連接查詢select sname from stud
4、ent,sc where student.sno=sc.sno and cno=002; 例:查詢與“劉晨”在同一個(gè)系學(xué)習(xí)的學(xué)生。-子查詢實(shí)現(xiàn)select * from student where sdept in(select sdept from student where sname=劉晨 ); -自身連接實(shí)現(xiàn)select b.sno,b.sname,b.sdept from student a,student b where a.sdept=b.sdept and a.sname= 劉晨 ; 例:查詢被學(xué)生選修過的課程信息select * from course where cno i
5、n(select distinct cno from sc); 例:查詢未被學(xué)生選修過的課程信息select * from course where cno not in(select distinct cno from sc); 例:查詢選修了課程名為“信息系統(tǒng)”的學(xué)生學(xué)號(hào)和姓名-子查詢實(shí)現(xiàn)select sno,sname from student where sno in( select sno from sc where cno in( select cno from course where cname= 信息系統(tǒng) ); -連接查詢實(shí)現(xiàn)select student.sno,sname
6、from student,sc,course where student.sno=sc.sno and o=o and cname=信息系統(tǒng) ; (執(zhí)行效率:一般dbms內(nèi)部按照連接查詢執(zhí)行。子查詢?cè)趦?nèi)部執(zhí)行時(shí)會(huì)先轉(zhuǎn)換為連接查詢,再執(zhí)行 ) 帶有 any(some )或 all 謂詞的子查詢例:查詢其他系中比cs系某一學(xué)生年齡小的學(xué)生姓名和年齡select sname,sage from student where sageany(select sage from student where sdept=cs) and sdeptcs; 或select sname,sage from stud
7、ent where sage(select max(sage) from student where sdept=cs) and sdeptcs; 例:查詢其他系中比cs系所有學(xué)生年齡都大的學(xué)生姓名及年齡。select sname,sage from student where sageall(select sage from student where sdept=cs) and sdeptcs; 或select sname,sage from student where sage(select max(sage) from student where sdept=cs) and sdept
8、cs; =any(與 in 等價(jià) ) any (min() any(all(max() all(select avg(grade) from sc where sno=a.sno); 例:查詢比本系平均年齡大的學(xué)生信息。select * from student a where sage(select avg(sage) from student where sdept=a.sdept); 出現(xiàn)在 having 后面的子查詢例:查詢選修了全部課程的學(xué)生姓名。select sno,sname from student where sno in( select sno from sc group
9、by sno having count(*)=(select count(*) from course); 例:查詢至少選修了學(xué)生08002 選修的全部課程的學(xué)生號(hào)碼。select sno from sc where cno in(select cno from sc where sno=08002) group by sno having count(*)=(select count(*) from sc where sno=08002); 例:查詢最小年齡大于cs系最小年齡的系別和其最小年齡。select sdept,min(sage) from student group by sdep
10、t having min(sage) (select min(sage) from student where sdept=cs); 出現(xiàn)在 from 后面的子查詢(派生表)例:查詢比本人平均成績(jī)高的學(xué)生學(xué)號(hào)和課程號(hào)。select sc.sno,cno,grade,avggrade from sc,(select sno,avg(grade) avggrade from sc group by sno) awhere sc.sno=a.sno and gradea.avggrade;并操作 union/union all 例:查詢計(jì)算機(jī)科學(xué)系的學(xué)生及年齡不大于19 歲的學(xué)生。select sname,sdept,sagefrom s
溫馨提示
- 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ù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 導(dǎo)電涂料項(xiàng)目安全評(píng)估報(bào)告
- 馬鈴薯淀粉生產(chǎn)建設(shè)項(xiàng)目可行性研究報(bào)告范文
- 2023-2029年中國(guó)在線教育平臺(tái)行業(yè)市場(chǎng)調(diào)查研究及發(fā)展戰(zhàn)略規(guī)劃報(bào)告
- 2025年黑管項(xiàng)目可行性研究報(bào)告
- 中國(guó)遮光斗項(xiàng)目投資可行性研究報(bào)告
- 6超微量分析天平大儀論證報(bào)告 - 浙江師范大學(xué)實(shí)驗(yàn)室管理處
- 中國(guó)防靜電潔凈室市場(chǎng)全景評(píng)估及投資規(guī)劃建議報(bào)告
- 2025年中國(guó)阿膠行業(yè)運(yùn)行態(tài)勢(shì)及未來(lái)發(fā)展趨勢(shì)預(yù)測(cè)報(bào)告
- 32004某火力發(fā)電廠安全預(yù)評(píng)價(jià)報(bào)告
- 2025年中國(guó)中重卡行業(yè)市場(chǎng)調(diào)查研究及投資前景預(yù)測(cè)報(bào)告
- WS 400-2023 血液運(yùn)輸標(biāo)準(zhǔn)
- 銀行業(yè)金融機(jī)構(gòu)監(jiān)管數(shù)據(jù)標(biāo)準(zhǔn)化規(guī)范(2021版)數(shù)據(jù)結(jié)構(gòu)一覽表
- 電子商務(wù)基礎(chǔ)與實(shí)務(wù)(第四版)高職PPT完整全套教學(xué)課件
- 信息論與編碼(第4版)完整全套課件
- 施工吊籃工程監(jiān)理實(shí)施細(xì)則
- 自動(dòng)扶梯與自動(dòng)人行道調(diào)試作業(yè)指導(dǎo)書(通用版)
- 2023年全國(guó)卷英語(yǔ)甲卷講評(píng)課件-2024屆高考英語(yǔ)復(fù)習(xí)
- 現(xiàn)代通信原理與技術(shù)(第五版)PPT全套完整教學(xué)課件
- 《戰(zhàn)勝抑郁 走出抑郁癥的30天自我康復(fù)訓(xùn)練》讀書筆記思維導(dǎo)圖
- 幼兒園課件:時(shí)鐘國(guó)王
- 最值問題-阿氏圓
評(píng)論
0/150
提交評(píng)論