05_oracel题集
1、已建立兩張學(xué)生基本信息表,表的結(jié)構(gòu)如下
Test
| No | Name | Sex | Age | Department | Place |
|---|---|---|---|---|---|
| 2002001 | 張三 | 男 | 20 | 計算機(jī)系 | 北京 |
| 2002002 | 李四 | 女 | 20 | 數(shù)學(xué)系 | 山東 |
| 2002003 | 王五 | 男 | 21 | 計算機(jī)系 | 北京 |
| 2002004 | 小紅 | 女 | 21 | 數(shù)學(xué)系 | 河北 |
| 2002005 | 小李 | 男 | 20 | 數(shù)學(xué)系 | 遼寧 |
| 2002006 | 小王 | 男 | 22 | 計算機(jī)系 | 浙江 |
Test1
| No | Grade | Courses |
|---|---|---|
| 2002001 | 87 | 英語 |
| 2002002 | 81 | 數(shù)學(xué) |
| 2002003 | 75 | 操作系統(tǒng) |
| 2002004 | 91 | 網(wǎng)絡(luò) |
| 2002005 | 70 | 數(shù)據(jù)庫 |
| 2002006 | 85 | C語言 |
1、 找出是計算機(jī)系并籍貫是北京的學(xué)生的所有記錄
2、 把計算機(jī)系的學(xué)生的Department改為信息學(xué)院
3、 連接查詢找出成績大于等于75分的學(xué)生的NO,Nname,Grade,Courses字段的記錄
1.select t.*,t1.grade,t1.course from test t,test1 t1 where t.no=t1.no and t.department='計算機(jī)系' and t.place='北京';
2.update test set department='信息學(xué)院' where department='計算機(jī)系';
3.select t.no,t.name,t1.grade,t1.courses from test t,test1 t1 where t.no=t1.no and t1.grade>75;
2、表的結(jié)構(gòu)如下
Student(s#,sname,sage,ssex)學(xué)生表
Course(c#,cname,t#)課程表
Sc(s#,c#,score)成績表
Teacher(t#,tname)教師表
查詢成績小于60分的學(xué)生姓名和課程名
查詢平均成績并排序
查詢學(xué)過“李華”老師所教的所有課程的同學(xué)的學(xué)號和姓名
修改“王小二”學(xué)生的“歷史”課成績,修改為85
刪除成績表
1.select s.sname, c.cname from student s,course c,sc where s.s#=sc.s# and c.c#=sc.c# and sc.score<60;
2.select avg(score) avgscore from sc group by s# order by avgscore;
select s.s#,s.sname from student s,
(select s.s#,count(sc.c#) count2 from student s,sc,
(select c.c# c1,count(c.c#) count1 from course c,teacher t
where c.c#=t.t# and t.tname='李華' --1--李華老師教的課程) a1
where s.s#=sc.s# and sc.c#=a1.c1 and count1=count2 --2) a2
where s.s#=a2.s#; --3
4.update 表名 set 列=值 where 條件
update sc set score=85 where s#=(select s# from student where sname='王小二')
and c#=(select c# from course where cname='歷史')
5.drop table sc
3、表的結(jié)構(gòu)如下
S(sno,sname) 學(xué)生關(guān)系。Sno為學(xué)號,sname為姓名
C(cno,cname,cteacher)課程關(guān)系。Cno為課程號,cname為課程名,cteacher為任課老師
Sc(sno,cno,scgrade)選課關(guān)系,scgrade為成績
(1) 找出沒有選修過“李明”老師講授課程的所有學(xué)生姓名
select s.sname from s,c,sc where s.sno=sc.sno and c.cno=sc.cno and c.cteacher !='李明';
(2) 列出有二門以上(含兩門)不及格課程的學(xué)生姓名及其平均成績
select s.sname ,a1.avggrade from s,
(select sno,avg(scgrade) avggrade from sc where scgrade<60 group by sno having count(*)>=2) a1
where s.sno=a1.sno;
(3) 列出既學(xué)過“1”號課程,又學(xué)過“2”號課程的所有學(xué)生姓名
select sname from s where sno in(
select sno from sc where cno=1
intersect
select sno from sc where cno=2);
3、在學(xué)生選課系統(tǒng)的后臺數(shù)據(jù)庫中,主要有3個表:
學(xué)生基本信息表stdinfo(學(xué)號SN,姓名Name,性別Sex,專業(yè)Speciality,出生年月Bady),
選課表Mycourse(學(xué)號SN、課程號CourseNum、分?jǐn)?shù)Credithour),
課程表Coursetab(課程號CourseNum,課程名Coursename,所屬專業(yè)Speciality, 分?jǐn)?shù)Credithour)
要求:寫出SQL語句。
1) 查詢所有SQL課程的學(xué)生學(xué)號,姓名和專業(yè)。
2) 查詢所有選計算機(jī)這門課程的學(xué)生學(xué)號,姓名和專業(yè),并按照學(xué)號降序排序
3) 刪除所有選擇數(shù)學(xué)的同學(xué)的選課記錄
4) 查詢有哪些課程有30個以上的同學(xué)報選
5) 查詢有哪些課程沒有被任何同學(xué)報選
1.select s.sn,s.name,c.speciality from stdinfo s,coursetab c where s.specaility=c.specaility and c.courename='SQL';
2.select s.sn,s.name,c.speciality from stdinfo s,coursetab c where s.specaility=c.specaility and c.courename='計算機(jī)' order by s.sn desc;
3.delete from mycourse where courseNum=(select coursenum from coursetab where coursename='數(shù)學(xué)')
4.select coursename from coursetab where coursenum in (select coursenum from mycourse group by coursenum having count(*)>30);
select coursename from coursetab where coursenum in
(select coursenum from coursetab
except
select distinct coursenum from mycourse)
4、以下有兩個表
表一 AAA
| Mc種類 | S1庫存總量 |
|---|---|
| A | 997 |
| B | 1234 |
表二 BBB
| Mc種類 | S1出庫數(shù)量 |
|---|---|
| A | 105 |
| A | 213 |
| B | 116 |
| B | 211 |
| B | 303 |
1) 分別寫出AAA的建表語句;
2) 用一條SQL語句求出A出庫的數(shù)量是多少?
3) 用一條SQL語句求出A,B各剩下多少?
2.select sum(s1出庫數(shù)量) from bbb where mc種類='A'
select a1.s1庫存總量-a2.outs1 from aaa a1,( select mc種類,sum(s1出庫數(shù)量) outs1 from bb group by mc種類) a2 where a1.mc種類=a2.mc種類
5、表結(jié)構(gòu)如下:
學(xué)生表:Student(S#,Sname,Sage,Ssex) ,學(xué)號:S#,學(xué)生姓名:Sname,學(xué)生年齡:Sage,學(xué)生性別:Ssex
課程表:Course(C#,Cname,T#),課程編號:C#,課程名字:Cname,教師編號:T#
成績表:SC(S#,C#,score), 學(xué)號:S#,課程編號:C#,成績:score
教師表:Teacher(T#,Tname),教師編號:T#,教師名字:Tname
問題:
1、查詢"001"課程比"002"課程成績高的所有學(xué)生的學(xué)號;
select a1.s# from
(select s#,score from sc where c#=001) a1,
(select s#,score from sc where c#=002) a2
where a1.s#=a2.s# and a1.score>a2.score;
2、刪除學(xué)習(xí)“葉平”老師課的SC表記錄;
delete from sc where c# in(select t.c# from course c1, teacher t where c1.t#=t.t# and t.tname='葉平')
3、向SC表插入一筆數(shù)據(jù)(S#:200806505; C#:201101, score:85);
insert into sc values(20080605,201101,85);
4、把"SC"表中“葉平”老師教的課的成績都更改為此課程的平均成績。
update sc set score=(select avg(score) from sc where c# =(select t.c# from course c1, teacher t where c1.t#=t.t# and t.tname='葉平'))
where c# =(select t.c# from course c1, teacher t where c1.t#=t.t# and t.tname='葉平'))
總結(jié)
以上是生活随笔為你收集整理的05_oracel题集的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微信签名的获取
- 下一篇: 【repost】JavaScript 事