




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、(一)新建以下幾個(gè)表student(學(xué)生表):snosnamesexdeptbirthage其中約束如下:(1)學(xué)號(hào)不能存在相同的(2)名字為非空(3)性別的值只能是男或女(4)系包括這幾個(gè):信息系,計(jì)算機(jī)科學(xué)系,數(shù)學(xué)系,管理系,中文系,外語(yǔ)系,法學(xué)系(5)出生日期為日期格式(6)年齡為數(shù)值型,且在0100之間createtablestudent(snosmallintconstraintaprimarykey,-設(shè)置學(xué)生學(xué)號(hào)為student的主鍵snamevarchar(10)notnull,sexvarchar(2)constraintbcheck(sexin('男',
2、39;女'),一檢查約束一性別的值只能是男或女deptvarchar(20)constraintccheck(deptin('信息系,計(jì)算機(jī)科學(xué)系,數(shù)學(xué)系,管理系,中文系',外語(yǔ)系,法學(xué)系),-檢查約束一源包括這幾個(gè):信息系,計(jì)算機(jī)科學(xué)系,數(shù)學(xué)系,管理系,中文系,外語(yǔ)系,法學(xué)系birthdatetime,agesmallintconstraintdcheck(agebetween0and100)-檢查約束一年齡為數(shù)值型,且在100之間)cs(成績(jī)表):snocnocj其中約束如下:(1) sno和cno分別參照student和course表中的sno,cno的字段(2)
3、 cj(成績(jī))只能在0100之間,可以不輸入值createtablecs(snosmallintnotnullreferencesstudent(sno),-定義成外鍵cnosmallintnotnullreferencescourse(cno),-定義成外鍵cjsmallintconstraintecheck(cjbetween0and100),-檢查約束一-cj(成績(jī))只能在100之間,可以不輸入值constraintfprimarykey(sno,cno)定義學(xué)生學(xué)號(hào)和課程號(hào)為sc表的主鍵)course(課程表)cnocname其約束如下:(1)課程號(hào)(cno)不能有重復(fù)的(2)課程名(
4、cname非空createtablecourse(cnosmallintnotnullconstraintgprimarykey,-設(shè)置課程號(hào)為course的主鍵cnamevarchar(20)notnull)(三)針對(duì)學(xué)生課程數(shù)據(jù)庫(kù)查詢(1) 查詢?nèi)w學(xué)生的學(xué)號(hào)與姓名。Selectsno,snamefromstudent(2) 查詢?nèi)w學(xué)生的姓名、學(xué)號(hào)、所在系,并用別名顯示出結(jié)果。Selectsnameas'姓名',snoas'學(xué)號(hào)',deptas所在地'fromstudent(3) 查詢?nèi)w學(xué)生的詳細(xì)記錄。select*fromstudent(4)
5、查全體學(xué)生的姓名及其出生年份。selectsname,birthfromstudent(5) 查詢學(xué)校中有哪些系select distinctdept from student(6) 查詢選修了課程的學(xué)生學(xué)號(hào)。selectsnofromcswherecnoisnotnull(7) 查詢所有年齡在20歲以下的學(xué)生姓名及其年齡。selectsname,agefromstudentwhereage<20(8) 查詢年齡在2023歲(包括20歲和23歲)之間的學(xué)生的姓名、系別和年齡。selectsname,dept,agefromstudentwhereagebetween20and23(9)
6、查詢年齡不在202野之間的學(xué)生姓名、系別和年齡。selectsname,dept,agefromstudentwhereage<20orage>23(10)查詢信息系、數(shù)學(xué)系和計(jì)算機(jī)科學(xué)系生的姓名和性別。selectsname,sexfromstudentwheredept=信息系ordept='數(shù)學(xué)系'ordept='計(jì)算機(jī)科學(xué)系(11)查詢既不是信息系、數(shù)學(xué)系,也不是計(jì)算機(jī)科學(xué)系的學(xué)生的姓名和性別。selectsname,sexfromstudentwheredept!='信息系anddept!=數(shù)學(xué)系'anddept!=計(jì)算機(jī)科學(xué)系(1
7、2)查詢所有姓劉學(xué)生的姓名、學(xué)號(hào)和性別。selectsname,sno,sexfromstudentwheresnamelike('劉')(13)查詢學(xué)號(hào)為2009011的學(xué)生的詳細(xì)情況。(具體的學(xué)號(hào)值根據(jù)表中數(shù)據(jù)確定)select*fromstudentwheresno=5(14)查詢姓“歐陽(yáng)”且全名為三個(gè)漢字的學(xué)生姓名selectsnamefromstudentwheresnamelike('歐陽(yáng))(15)查詢名字中第2個(gè)字為“晨”字的學(xué)生的姓名和學(xué)號(hào)selectsname,snofromstudentwheresnamelike('_晨')(16)
8、查詢所有不姓劉的學(xué)生姓名。selectsname,snofromstudentwheresnamenotlike('劉')(17)查詢sql課程的課程號(hào)和學(xué)分。selectcnofromcoursewherecname='sql'(18)查詢以“DB_"開頭,且倒數(shù)第3個(gè)字符為i的課程的詳細(xì)情況。select*fromcoursewherecnamelike('DBi_')(19)查詢?nèi)鄙俪煽?jī)的學(xué)生的學(xué)號(hào)和相應(yīng)的課程號(hào)。selectsno,cnofromcswherecjisnull(20)查所有有成績(jī)的學(xué)生學(xué)號(hào)和課程號(hào)。selects
9、no,cnofromcswherecjisnotnull(21)查詢計(jì)算機(jī)系年齡在20歲以下的學(xué)生姓名。selectsnamefromstudentwhereage<20anddept='計(jì)算機(jī)科學(xué)系(22)查詢信息系、數(shù)學(xué)系和計(jì)算機(jī)科學(xué)系學(xué)生的姓名和性別。(使用多個(gè)條件表達(dá)式)selectsname,sexfromstudentwheredept=信息系ordept='數(shù)學(xué)系'ordept='計(jì)算機(jī)科學(xué)系(23)查詢年齡在2023歲(包括20歲和23歲)之間的學(xué)生的姓名、系別和年齡。(使用多個(gè)條件表達(dá)式)selectsname,dept,agefroms
10、tudentwhereagebetween20and23(24)查詢選修了3號(hào)課程的學(xué)生的學(xué)號(hào)及其成績(jī),查詢結(jié)果按分?jǐn)?shù)降序排列。selectsno,cjfromcswherecno=3orderbycjdesc(25)查詢?nèi)w學(xué)生情況,查詢結(jié)果按所在系的系號(hào)升序排列,同一系中的學(xué)生按年齡降序排列。select*fromstudentorderbydeptasc,agedesc(26)查詢學(xué)生總?cè)藬?shù)。selectcount(*)fromstudent(27)查詢選修了課程的學(xué)生人數(shù)。selectcount(sno)fromcswherecnoisnotnull(28)計(jì)算1號(hào)課程的學(xué)生平均成績(jī)。
11、selectavg(cj)fromcswherecno=1(29)查詢選修1號(hào)課程的學(xué)生最高分?jǐn)?shù)。selectmax(cj)fromcswherecno=1(30)求各個(gè)課程號(hào)及相應(yīng)的選課人數(shù)。o,count(cs.sno)o=o(31)查詢選修了3門以上課程的學(xué)生學(xué)號(hào)。selectsno,count(cno)fromcsgroupbysnohavingcount(cno)>3(32)查詢有3門以上課程是90分以上的學(xué)生的學(xué)號(hào)及(90分以上的)課程數(shù)。selectsno,count(cno)as'課程數(shù)'fro
12、mcswherecj>90groupbysnohavingcount(cno)>=3(33)查詢學(xué)生2006011選修課程的總學(xué)分。selectsum(course)fromcourse,cswhereo=cs.snoandcs.sno=2006011(34)查詢每個(gè)學(xué)生選修課程的總學(xué)分。selectsno,sum(cj)fromcs,courseo=ogroupbysnounionselectsno,0fromstudentwheresnonotin(selectsnofromcs)(35)查詢每個(gè)學(xué)生及其選修課程的情況。selectcs.sno,course.*fromcs,c
13、oursewhereo=o(36)查詢選修2號(hào)課程且成績(jī)?cè)?0分以上的所有學(xué)生的學(xué)號(hào)、姓名selectsno,snamefromstudentwheresno=(selectsnofromcswherecno=2andcj>90)(37)查詢每個(gè)學(xué)生的學(xué)號(hào)、姓名、選修的課程名及成績(jī)。selectstudent.sno,sname,course.course,cs.cjfromstudent,course,cswherestudent.sno=o=o(38)查詢與“劉晨”在同一個(gè)系學(xué)習(xí)的學(xué)生(分別用嵌套查詢和連接查詢)-嵌套查詢select*fromstudentwheredeptin(s
14、electdeptfromstudentwhere sname ='劉晨select stui* from studentas stui , student as連接查詢stu2where stul.dept =stu2 . deptand stu2 . sname =劉晨'-exists查詢selectfrom student siwhere exists(select*fromstudents2wheresi.dept=s2.deptands2.sname='劉晨'(39)查詢選修了課程名為“信息系統(tǒng)”的學(xué)生學(xué)號(hào)和姓名selectsno,snamefroms
15、tudentwheresnoin(selectsnofromcswherecnoin(selectcnofromcoursewherecname='信息系統(tǒng)')(40)查詢其他系中比信息系任意一個(gè)(其中某一個(gè))學(xué)生年齡小的學(xué)生姓名和年齡selectsname,agefromstudentwhereage<any(selectagefromstudentwheredept='信息系(41)查詢其他系中比信息系所有學(xué)生年齡都小的學(xué)生姓名及年齡。分別用ALL胃詞和集函數(shù)用ALLselectsname,agefromstudentwhereage<all(selec
16、tagefromstudentwheredept='信息系')聚合函數(shù)selectsname,agefromstudentwhereage<(selectmin(age)fromstudentwheredept='信息系)查詢所有選修了 1號(hào)課程的學(xué)生姓名(42)- 嵌套查詢 select sname(select sno-一連接查詢select sname where student(分別用嵌套查詢和連查詢)from studentfrom cs wherefrom student.sno =cs . snowhere sno incno =1),csand c
17、s . cno = 1(43)查詢沒有選修1號(hào)課程的學(xué)生姓名。selectsnamefromstudentwheresnoin(selectsnofromcswherecno!=1)(44)查詢選修了全部課程的學(xué)生姓名selectsnamefromstudentwherenotexists(select*fromcoursewherenotexists(select*fromcswherecs.sno=student.snoando=o)(45)查詢至少選修了學(xué)生95002選修的全部課程的學(xué)生號(hào)碼select distinctsno from sc scxwhere notexists(sel
18、ect* from cs scyand not exists(select* from sc sczwhere scy . sno ='95002where scz . sno =scx . snoand scz . cno =scy . cno )(46)查詢計(jì)算機(jī)科學(xué)系的學(xué)生及年齡不大于19歲的學(xué)生的信息select * from studentwhere dept ='計(jì)算機(jī)科學(xué)系'orage<19(47)查詢選修了課程1或者選修了課程2的學(xué)生的信息。selectstudent.*fromstudent,cswherestudent.sno=cs.snoan
19、d(o=1oro=2)(48)查詢計(jì)算機(jī)科學(xué)系中年齡不大于19歲的學(xué)生的信息。select*fromstudentwhereage<=19anddept=計(jì)算機(jī)科學(xué)系(49)查詢既選修了課程1又選修了課程2的學(xué)生的信息。select*fromstudentwheresnoin(selectsnofromcswherecno='003'andsnoin(selectsnofromcswherecno='004')-用exists查詢select*fromstudentwhereexists(select*fromcswherestudent.sno=cs.snoandcno='003'andsnoin(selectsnofromcswherecno='004')(50)查詢計(jì)算機(jī)科學(xué)系的學(xué)生與年齡不大于19歲的學(xué)生的差集。select*fromstud
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 衡陽(yáng)成章八下數(shù)學(xué)試卷
- 廣西聯(lián)考高三數(shù)學(xué)試卷
- 河西區(qū)歷年中考數(shù)學(xué)試卷
- 河南省2024新高考數(shù)學(xué)試卷
- 2025-2030中國(guó)盒子和紙箱外包裝膜行業(yè)市場(chǎng)發(fā)展趨勢(shì)與前景展望戰(zhàn)略研究報(bào)告
- 2025-2030中國(guó)消毒蒸汽發(fā)生器行業(yè)市場(chǎng)發(fā)展趨勢(shì)與前景展望戰(zhàn)略研究報(bào)告
- 中班健康拖地板課件
- 機(jī)器人輔助養(yǎng)殖-洞察及研究
- 衡水下學(xué)期四調(diào)數(shù)學(xué)試卷
- 貴州18高考數(shù)學(xué)試卷
- 【公開課】三角形的邊+課件+2025-2026學(xué)年人教版八年級(jí)數(shù)學(xué)上冊(cè)
- 2025年廣東省普通高中學(xué)業(yè)水平合格性考試模擬一歷史試題(含答案)
- 【公開課】+分子動(dòng)理論的初步知識(shí)(教學(xué)課件)2025-2026學(xué)年初中物理人教版(2024)九年級(jí)全一冊(cè)
- 設(shè)備安全培訓(xùn)
- 2025至2030中國(guó)角膜塑形鏡行業(yè)產(chǎn)業(yè)運(yùn)行態(tài)勢(shì)及投資規(guī)劃深度研究報(bào)告
- 2023aki的預(yù)防診斷和管理
- 2025年4月自考03346項(xiàng)目管理試題
- 慢性腎衰竭患者心理的護(hù)理
- 艾梅乙反歧視培訓(xùn)課件
- 小學(xué)數(shù)學(xué)課堂教學(xué)實(shí)踐與創(chuàng)新
- 2024年安徽外國(guó)語(yǔ)學(xué)院輔導(dǎo)員考試真題
評(píng)論
0/150
提交評(píng)論