




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、sql語句練習(xí)題及答案表。一 在數(shù)據(jù)庫 school 中建立 student , sc, course學(xué)生表、課程表、選課表屬于數(shù)據(jù)庫 School , 其各自的數(shù)據(jù)結(jié)構(gòu)如下:學(xué)生 Stude nt (Sno,S name,Ssex,Sage,Sde pt)序口, 號(hào)列名含義數(shù)據(jù)類型長度1Sno學(xué)號(hào)字符型(char)62Sn ame姓名字符型(varchar)83Ssex性別字符型(char)24Sage年齡整數(shù)(smalli nt)5sde pt系科字符型(varchar)15課程表course(Cno,C name,C pn o,Ccredit)序列名含義數(shù)據(jù)類型長口 號(hào)度1Cno課程口,
2、 號(hào)字符型(char)42cn ame課程名字符型(varchar)203Cpno先修課字符型(char)44Ccredi t學(xué)分短整數(shù)(ti nyi nt)學(xué)生選課 SC(Sno,Cno.Grade)序口, 號(hào)列名含義數(shù)據(jù)類型長度1Sno學(xué)號(hào)字符型(char)62Cno課程口, 號(hào)字符型(char)43Grade成績小數(shù)(decimal)12,2二設(shè)定主碼1 Student表的主碼:sno2 Course表的主碼:eno3 Se表的主碼:sno,eno 1寫出使用 Create Table 語句創(chuàng)建表student se, course 的 SQL語句2在student表中插入信息學(xué)號(hào)姓匚名
3、性別年齡系科4001趙茵男20SX4002楊華女21JSJ3刪除student表中的元組4在數(shù)據(jù)庫school中刪除關(guān)系student5在 student表添加屬性 datetimesbirthdate 類型練習(xí)Delete1刪除所有JSJ系的男生 delete fromStude nt where Sdept= 'SJ' a nd Ssex='男 '2刪除 數(shù)據(jù)庫原理”勺課的選課紀(jì)錄Up date12delete from SC where Cno in (select Cno fromCourse where Cname='數(shù)據(jù)庫原理'修改0
4、001學(xué)生的系科為:JSJ把陳小明的年齡加1歲,性別改為女。 修改李文慶的1001課程的成績?yōu)?3分 把 數(shù)據(jù)庫原理”課的成績減去1分Select查詢語句一單表1查詢年齡在19至21歲之間的女生的學(xué)號(hào),姓 名,年齡,按年齡從大到小排列。2查詢姓名中第2個(gè)字為“明"字的學(xué)生學(xué)號(hào)、 性別??谔?hào)、3查詢1001課程沒有成績的學(xué)生學(xué)號(hào)、課程號(hào)4查詢JSJ、SX WL系的年齡大于25歲的學(xué)生 學(xué)號(hào),姓名,結(jié)果按系排列5按10分制查詢學(xué)生的sno,cno,10分制成績(1-10 分為 1,11-20 分為 2,30-39 分為 3,。90-100 為 10)6查詢student 表中的學(xué)生共分布
5、在那幾個(gè)系 中。(distinct )7查詢0001號(hào)學(xué)生1001,1002課程的成績。二統(tǒng)計(jì)1查詢姓名中有"明"字的學(xué)生人數(shù)。2計(jì)算JSJ'系的平均年齡及最大年齡。3查詢學(xué)生中姓名為張明、趙英的人數(shù)4計(jì)算每一門課的總分、平均分,最高分、最低 分,按平均分由高到低排列計(jì)算1001,1002課程的平均分。查詢平均分大于80分的學(xué)生學(xué)號(hào)及平均分 統(tǒng)計(jì)選修課程超過2門的學(xué)生學(xué)號(hào) 統(tǒng)計(jì)有10位成績大于85分以上的課程號(hào)。統(tǒng)計(jì)平均分不及格的學(xué)生學(xué)號(hào)三連接1查詢JSJ2查詢選修 嵌套及嵌套10統(tǒng)計(jì)有大于兩門課不及格的學(xué)生學(xué)號(hào)系的學(xué)生選修的課程號(hào)1002課程的學(xué)生的學(xué)生姓名(不用
6、2種方法)3查詢數(shù)據(jù)庫原理不及格的學(xué)生學(xué)號(hào)及成績4查詢選修“數(shù)據(jù)庫原理”課且成績 80以上的 學(xué)生姓名(不用嵌套及嵌套2種方法)平均5查詢平均分不及格的學(xué)生的學(xué)號(hào),姓名, 分。6查詢女學(xué)生平均分高于75分的學(xué)生姓名。7查詢男學(xué)生學(xué)號(hào)、姓名、課程號(hào)、成績。 門課程也沒有選修的男學(xué)生也要列出,不能遺 漏) 四嵌套、相關(guān)及其他1查詢平均分不及格的學(xué)生人數(shù)2查詢沒有選修1002課程的學(xué)生的學(xué)生姓名3查詢平均分最高的學(xué)生學(xué)號(hào)及平均分(2種方法 TOP , any , all )*4查詢沒有選修1001,1002課程的學(xué)生姓名。5查詢1002課程第一名的學(xué)生學(xué)號(hào)(2種方法)6查詢平均分前三名的學(xué)生學(xué)號(hào)7查
7、詢JSJ系的學(xué)生與年齡不大于 19歲的學(xué) 生的差集可、8查詢1001號(hào)課程大于90分的學(xué)生學(xué)號(hào)、姓名及平均分大于85分的學(xué)生學(xué)號(hào)、姓名9查詢每門課程成績都高于該門課程平均分的 學(xué)生學(xué)號(hào)10查詢大于本系科平均年齡的學(xué)生姓名答案參考答案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='數(shù)據(jù)庫 原理'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='數(shù)據(jù)庫原理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='數(shù)據(jù)庫原理')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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 房地產(chǎn)銷售經(jīng)理個(gè)人年終工作總結(jié)(28篇)
- 小學(xué)教師教育教學(xué)反思與自我提高策略試題及答案
- 環(huán)境監(jiān)測(cè)材料采購協(xié)議
- 民辦教育機(jī)構(gòu)2025年合規(guī)運(yùn)營與品牌推廣效果評(píng)估報(bào)告
- 建筑防水材料試題及答案
- 化州中考英語試題及答案
- 大學(xué)化學(xué)考試教師指導(dǎo)策略分析題目及答案
- 購房者權(quán)益及責(zé)任說明
- 大慶語文教招試題及答案
- 教室資格測(cè)試題及答案
- 2025年黑龍江牡丹江市“雪城優(yōu)才”招聘事業(yè)單位480人歷年高頻重點(diǎn)模擬試卷提升(共500題附帶答案詳解)
- 5.1 根本政治制度 同步練習(xí) -2024-2025學(xué)年統(tǒng)編版道德與法治八年級(jí)下冊(cè)
- 2024年03月全國北京銀行總行社會(huì)招考(315)筆試歷年參考題庫附帶答案詳解
- 自動(dòng)化儀表項(xiàng)目可行性研究報(bào)告
- 業(yè)主代表大會(huì)決議范文
- 2023版肝硬化腹水診療指南解讀
- 《香格里拉松茸保護(hù)與利用白皮書》
- 先天性高胰島素性低血糖血癥病因介紹
- 《前列腺癌篩查及治療的臨床研究進(jìn)展》
- 11.5 歌曲《賣報(bào)歌》課件(14張)
- 小學(xué)英語語法專題訓(xùn)練:名詞所有格(含答案)
評(píng)論
0/150
提交評(píng)論