![sql語句練習題及答案_第1頁](http://file3.renrendoc.com/fileroot_temp3/2022-1/24/46a72346-0657-46c3-bde2-9497f1234071/46a72346-0657-46c3-bde2-9497f12340711.gif)
![sql語句練習題及答案_第2頁](http://file3.renrendoc.com/fileroot_temp3/2022-1/24/46a72346-0657-46c3-bde2-9497f1234071/46a72346-0657-46c3-bde2-9497f12340712.gif)
![sql語句練習題及答案_第3頁](http://file3.renrendoc.com/fileroot_temp3/2022-1/24/46a72346-0657-46c3-bde2-9497f1234071/46a72346-0657-46c3-bde2-9497f12340713.gif)
![sql語句練習題及答案_第4頁](http://file3.renrendoc.com/fileroot_temp3/2022-1/24/46a72346-0657-46c3-bde2-9497f1234071/46a72346-0657-46c3-bde2-9497f12340714.gif)
![sql語句練習題及答案_第5頁](http://file3.renrendoc.com/fileroot_temp3/2022-1/24/46a72346-0657-46c3-bde2-9497f1234071/46a72346-0657-46c3-bde2-9497f12340715.gif)
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、sql語句練習題及答案表。一 在數據庫 school 中建立 student , sc, course學生表、課程表、選課表屬于數據庫 School , 其各自的數據結構如下:學生 Stude nt (Sno,S name,Ssex,Sage,Sde pt)序口, 號列名含義數據類型長度1Sno學號字符型(char)62Sn ame姓名字符型(varchar)83Ssex性別字符型(char)24Sage年齡整數(smalli nt)5sde pt系科字符型(varchar)15課程表course(Cno,C name,C pn o,Ccredit)序列名含義數據類型長口 號度1Cno課程口,
2、 號字符型(char)42cn ame課程名字符型(varchar)203Cpno先修課字符型(char)44Ccredi t學分短整數(ti nyi nt)學生選課 SC(Sno,Cno.Grade)序口, 號列名含義數據類型長度1Sno學號字符型(char)62Cno課程口, 號字符型(char)43Grade成績小數(decimal)12,2二設定主碼1 Student表的主碼:sno2 Course表的主碼:eno3 Se表的主碼:sno,eno 1寫出使用 Create Table 語句創(chuàng)建表student se, course 的 SQL語句2在student表中插入信息學號姓匚名
3、性別年齡系科4001趙茵男20SX4002楊華女21JSJ3刪除student表中的元組4在數據庫school中刪除關系student5在 student表添加屬性 datetimesbirthdate 類型練習Delete1刪除所有JSJ系的男生 delete fromStude nt where Sdept= 'SJ' a nd Ssex='男 '2刪除 數據庫原理”勺課的選課紀錄Up date12delete from SC where Cno in (select Cno fromCourse where Cname='數據庫原理'修改0
4、001學生的系科為:JSJ把陳小明的年齡加1歲,性別改為女。 修改李文慶的1001課程的成績?yōu)?3分 把 數據庫原理”課的成績減去1分Select查詢語句一單表1查詢年齡在19至21歲之間的女生的學號,姓 名,年齡,按年齡從大到小排列。2查詢姓名中第2個字為“明"字的學生學號、 性別。口號、3查詢1001課程沒有成績的學生學號、課程號4查詢JSJ、SX WL系的年齡大于25歲的學生 學號,姓名,結果按系排列5按10分制查詢學生的sno,cno,10分制成績(1-10 分為 1,11-20 分為 2,30-39 分為 3,。90-100 為 10)6查詢student 表中的學生共分布
5、在那幾個系 中。(distinct )7查詢0001號學生1001,1002課程的成績。二統(tǒng)計1查詢姓名中有"明"字的學生人數。2計算JSJ'系的平均年齡及最大年齡。3查詢學生中姓名為張明、趙英的人數4計算每一門課的總分、平均分,最高分、最低 分,按平均分由高到低排列計算1001,1002課程的平均分。查詢平均分大于80分的學生學號及平均分 統(tǒng)計選修課程超過2門的學生學號 統(tǒng)計有10位成績大于85分以上的課程號。統(tǒng)計平均分不及格的學生學號三連接1查詢JSJ2查詢選修 嵌套及嵌套10統(tǒng)計有大于兩門課不及格的學生學號系的學生選修的課程號1002課程的學生的學生姓名(不用
6、2種方法)3查詢數據庫原理不及格的學生學號及成績4查詢選修“數據庫原理”課且成績 80以上的 學生姓名(不用嵌套及嵌套2種方法)平均5查詢平均分不及格的學生的學號,姓名, 分。6查詢女學生平均分高于75分的學生姓名。7查詢男學生學號、姓名、課程號、成績。 門課程也沒有選修的男學生也要列出,不能遺 漏) 四嵌套、相關及其他1查詢平均分不及格的學生人數2查詢沒有選修1002課程的學生的學生姓名3查詢平均分最高的學生學號及平均分(2種方法 TOP , any , all )*4查詢沒有選修1001,1002課程的學生姓名。5查詢1002課程第一名的學生學號(2種方法)6查詢平均分前三名的學生學號7查
7、詢JSJ系的學生與年齡不大于 19歲的學 生的差集可、8查詢1001號課程大于90分的學生學號、姓名及平均分大于85分的學生學號、姓名9查詢每門課程成績都高于該門課程平均分的 學生學號10查詢大于本系科平均年齡的學生姓名答案參考答案1 create table stude nt(snosn amessexchar(6), varchar(8), char(2), smalli nt, varchar(15),sagesde pt p rimary key(s no);create table sc(snochar(6),char(4), decimal(12,2),enogradep rima
8、ry key(s no,c no);in sert into stude ntvalues( ' 4001','趙茵','男,20,'SX') delete from stude nt drop table stude nt alter table stude nt add sbirthdate datetime1 select sno, sn ame, sagefromstude ntwhere ssex='女' and sage between 19 and 21 order by sage desc;2 select
9、 sno, ssexfromstude ntwhere sname like '明 % ' ;3 select sno, enofrom scwhere grade is n ull and cno= ' 1001'4 select sno, sn amefrom stude ntwhere sdept in (' JSJ' ,' SX' ,' WL ' ) and sage>25group by sde pt;select sno, eno, grade/10.0+1 as levelfrom sc ;se
10、lect dist inct sde pt from stude nt ;select gradefrom sccno='where sno= '0001' and (cno=' 1001' or 1002');coun t(*) from stude nt where sn ame % 明 % 'select like ' select avg(sage),max(sage) from student where sdept=' JSJ'select cn o,sum(grade),avg(grade),max(
11、grade),mi n(grade) from segroup by enoorder by avg(grade) dese ;select eno, avg(grade) from se where cnc in( 1001' ,' 1002')gro up by eno ;select se.s no ,avg(grade) from segro up by se.s nohav ing avg(grade)>80 ;select sno from se group by sno having eou nt(*)>2 ;select eno from s
12、e where grade>85 group by eno hav ing coun t(*)=10 ;select sno from se group by sno having avg(grade)<60 ;select enoselect sno from se where grade<60 group by sno hav ing coun t(*)>2 ;fromstude nt,scwherestudent.sno=sc.sno and sdept=' JSJ'a:select sn ame fromstude nt,scwherestude
13、 nt.s no=sc.s no and cno=' 1002' b:select sn ame from stude nt where sno in (select sno from sc where cno= ' 1002') select sn o,grade from sc,coursewhere o=o and cname='數據庫 原理'and grade <60 a:select sn ame from stude nt ,sc,courseandwherestude nt.s no=sc.s noo=o and grade&
14、gt;80 and cname='數據庫原理b:select sn ame from stude nt where sno in(select sno from sc where grade>80 and eno in (select eno from course where cn ame='數據庫原理')select sn o,s name,avg(grade) from sc,stude ntwhere stude nt.s no=sc.s no group by stude nt.s nohav ing avg(grade)<60a:select s
15、n ame from stude nt where ssex='女' and sno in( select sno from sc group by snohav ing avg(grade)>75)b:select sn ame from sc,stude nt where stude nt.s no=sc.s no and ssex=女'gro up bystude nt.s nohav ingavg(grade)>75select stude nt.s no,s name,c no,grade from stude nt left jo in sc o
16、n stude nt.s no=sc.s noand ssex='男'select coun t(*) from stude nt where sno in( select sno from sc group by sno hav ingavg(grade)v60)select sname from student where sno not in (select sno from sc where cno=' 1002')stude nt0001aaX0002bb0003ccXSc00011001000110020002100100031002Select s
17、name from student where not exists(select* from sc where cno= ' 1002'and sc.s no=stude nt.s no)a:select top 1 sno,avg(grade) from sc group by sno order by avg(grade) descb:select sno, avg(grade) from sc gro up by sno having avg(grade)=(select top 1 avg(grade) from scgro up by sno order by av
18、g(grade) desc) c:select sno, avg(grade) from sc group by snohaving avg(grade)>=all ( select avg(grade) from sc gro up by sno) select sn ame from stude nt where not exists( select * from course where eno in( "1001',' 1002' ) andnot exists(select * from sc where sno =stude nt.s no and eno=course.c no) a:select top 1 sno from sc cno=' 1002' order by grade descb:select sno from sc where cno=' 1002' andgrade >=all (and grade>90select sno,sname from student (select grade
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年排氣系統(tǒng)管件合作協(xié)議書
- 人教版期中測試卷-四年級數學下冊(培優(yōu)卷)(含解析)
- 2025年九年級教研組年終總結樣本(3篇)
- 2025年乳膠漆粉刷施工合同協(xié)議(2篇)
- 2025年產品買賣合同范文(2篇)
- 2025年二手房分期購房合同(三篇)
- 2025年個人車位租賃合同參考模板(三篇)
- 2025年臨時商鋪租賃合同簡單版(2篇)
- 2025年買賣合同黃金現貨(三篇)
- 2025年個人消費貸款合同(三篇)
- (正式版)HGT 6313-2024 化工園區(qū)智慧化評價導則
- 《社區(qū)康復》課件-第六章 骨關節(jié)疾病、損傷患者的社區(qū)康復實踐
- 南通市2024屆高三第二次調研測試(二模)地理試卷(含官方答案)
- 中外歷史綱要上大事年表
- 高標準農田建設項目監(jiān)理計劃
- 2024年湖南省公務員考試行政職業(yè)能力測驗真題
- 攀巖運動之繩結技巧課程
- 防打架毆斗安全教育課件
- 小學二年級(上冊)-乘法口訣-練習題-A4直接打印
- 采購行業(yè)的swot分析
- 石家莊長安區(qū)幼兒園信息統(tǒng)計表
評論
0/150
提交評論