


下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、SQLSERVER一、建數(shù)據(jù)表格,并添加數(shù)1、建立Student表數(shù)據(jù)createtableStudent(S#varchar(10),Snamenvarchar(10),Sage datetime,Ssex nvarchar(10)SQLSERVER一、建數(shù)據(jù)表格,并添加數(shù)1、建立Student表數(shù)據(jù)createtableStudent(S#varchar(10),Snamenvarchar(10),Sage datetime,Ssex nvarchar(10)o,2、建立Course表數(shù)據(jù)tableCourse(C#nvarchar(10),T#oN語文N數(shù)學N英語,3、建立Teacher
2、表數(shù)據(jù)tableTeacher(T#varchar(10),Tnameo,4、建立sc表3、建立Teacher表數(shù)據(jù)tableTeacher(T#varchar(10),Tnameo,4、建立sc表tableSC(S#o,o,o,二、用這些創(chuàng)建好的表進行數(shù)1、查詢01課程比02課程成績高的學生的信息及課程selecta.*,b.score,c.scorefromstudenta,scb,sccwherea.s#=b.s#and a.s#=c.s# and b.c#=01 and c.c#=02 and b.scorec.score2、查詢平均成績大于等于 60 分的同學的學和學和平均成#學號,
3、cast(avg(b.score)asdecimal(8,2)平均fromStudenta,scbwheregroupbya.s#,a.snamehavingavg(b.score)=60 order by a.s#cast為強制轉(zhuǎn)換語句,decimal可以指定小數(shù)點前后的位數(shù),avg求平數(shù)3、cast為強制轉(zhuǎn)換語句,decimal可以指定小數(shù)點前后的位數(shù),avg求平數(shù)3、查詢所有同學的學、選課總數(shù)、所有課程總成績Studenta,SCbya.s#,a.sname by a.s#4、查詢李姓老師的count(Tname李姓老師的數(shù)量fromTeacherwhereTnameCOUNT(*fro
4、mTeacherwhereTnamelike李COUNT(*) 李姓老師數(shù)量fromTeacherwhere4、查詢學過老師授課的同學的信selecta.*from4、查詢學過老師授課的同學的信selecta.*fromStudenta,SC,Course,Teacherwherea.S#=SC.S#SC.C#=Course.C#andandselectdistinctStudent.*fromStudent,SC,Course,andTeacher.Tname=orderbydistinct 用于返回唯一不同的5、查詢沒學過老師授課的同selectm.*fromStudentmwhereS#
5、notin(selectdistinctSC.S#fromSC, Course,TeacherwhereSC.C#=Course.C#andCourse.T#=Teacher.T#Teacher.Tname = ) order by 6、查詢學為01并且6、查詢學為01并且也為02的課程的同學的信selectStudent.*fromStudent,SCwhereStudent.S#=SC.S#andSC.C#= 01andexists(Select1fromSCSC_2whereSC_2.S#=SC.S#and= 02) order by selectStudent.*fromStudent
6、,SCwhereStudent.S#=SC.S#andSC.C#= 02andexists(Select1fromSCSC_2whereSC_2.S#=SC.S#and= 01) order by selectm.*fromStudentmwhereS#in selectS#from selectdistinctS#fromSCwhereC#=01 union allselect distinct S# from SC where C# = ) t group by S# having count(1) =)order by 7查詢?yōu)?1但是沒有7查詢?yōu)?1但是沒有學為02的課程的同學的信se
7、lectStudent.*fromStudent,SCwhereStudent.S#=SC.S#andSC.C#= 01andnotexists(Select1fromSCSC_2whereSC_2.S#=SC.S#and= 02) order by selectStudent.*fromStudent,SCwhereStudent.S#=SC.S#andSC.C#= 01andStudent.S#notin(SelectSC_2.S#fromSCSC_2whereSC_2.S#= SC.S# and SC_2.C# = 02) order by Student.S#8、查詢沒有學全所有課程的
8、同學的信方法一:selectStudent.*fromStudentSCwhereStudent.SgroupbyStudent.S#,Student.Sname,Student.Sage,Student.Ssexhaving count(C#) (select count(C#) from Course)方法二:selectStudent.*fromStudentleftjoinSConStudent.SgroupbyStudent.S#,Student.Sname,Student.Sage,Student.Ssexhaving count(C#) (select count(C#) from Course)9、查詢至少有一門課與學號為01的同學9、查詢至少有一門課與學號為01的同學所學相同的同學的selectdistinctStudent.*fromStudent,SCwhereStudent.S#=SC.S#and SC.C# in (select C# from SC where S# = 01) and Student.S# 0110、查詢和01號的同學學習的課程完全相同的其他同學的whereS#01andSC.C#in(selectdistinctC#fromSCwhereS#=01) 11、查詢沒學過老師講授的任一門課程
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 勞保棉衣采購合同范本
- 吉利產(chǎn)品購銷合同范本
- 香連金黃散外敷防治腹腔鏡下腹股溝疝修補術(shù)后血清腫的臨床研究
- 商用套房轉(zhuǎn)讓合同范本
- 別墅自己裝修合同范本
- 商城商鋪招租合同范例
- 商鋪集中出租合同范本
- 化學用品合同范例
- 合同范例 文化藝術(shù)
- 和二房東合租合同范本
- 《鈉離子電池產(chǎn)業(yè)發(fā)展白皮書》
- 2025中考作文預測
- 油氣田開發(fā)專業(yè)危害因素辨識與風險防控
- 假肢安裝合同范本
- DB37-T4824-2025 鄉(xiāng)鎮(zhèn)(街道)應急物資配備指南
- 教育部人文社科 申請書
- 無菌手術(shù)臺鋪置的細節(jié)管理
- 《重大基礎(chǔ)設(shè)施項目涉及風景名勝區(qū)選址論證報告編制技術(shù)規(guī)范》編制說明
- 議論文8(試題+審題+范文+點評+素材)-2025年高考語文寫作復習
- 2025年中國中煤能源股份有限公司招聘筆試參考題庫含答案解析
- 2025-2030年(全新版)中國軟冰淇淋市場發(fā)展趨勢與投資戰(zhàn)略研究報告
評論
0/150
提交評論