大学考试数据库试题_第1页
大学考试数据库试题_第2页
大学考试数据库试题_第3页
大学考试数据库试题_第4页
大学考试数据库试题_第5页
已阅读5页,还剩20页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

超完整、大学数据库考试试题包括46道循序渐进的试题及答案。假如感觉本文档对您的学习工作有协助,请用积分下载来支持我们。createtablestudent(

snovarchar2(10)primarykey,

snamevarchar2(20),

sagenumber(2),

ssexvarchar2(5)

);

createtableteacher(

tnovarchar2(10)primarykey,

tnamevarchar2(20)

);

createtablecourse(

cnovarchar2(10),

cnamevarchar2(20),

tnovarchar2(20),

constraintpk_courseprimarykey(cno,tno)

);

createtablesc(

snovarchar2(10),

cnovarchar2(10),

scorenumber(4,2),

constraintpk_scprimarykey(sno,cno)

);

/*******初始化学生表的数据******/

insertintostudentvalues('s001','张三',23,'男');

insertintostudentvalues('s002','李四',23,'男');

insertintostudentvalues('s003','吴鹏',25,'男');

insertintostudentvalues('s004','琴沁',20,'女');

insertintostudentvalues('s005','王丽',20,'女');

insertintostudentvalues('s006','李波',21,'男');

insertintostudentvalues('s007','刘玉',21,'男');

insertintostudentvalues('s008','萧蓉',21,'女');

insertintostudentvalues('s009','陈萧晓',23,'女');

insertintostudentvalues('s010','陈美',22,'女');

commit;

/******************初始化教师表***********************/

insertintoteachervalues('t001','刘阳');

insertintoteachervalues('t002','谌燕');

insertintoteachervalues('t003','胡明星');

commit;

/***************初始化课程表****************************/

insertintocoursevalues('c001','J2SE','t002');

insertintocoursevalues('c002','Java

Web','t002');

insertintocoursevalues('c003','SSH','t001');

insertintocoursevalues('c004','Oracle','t001');

insertintocoursevalues('c005','SQLSERVER','t003');

insertintocoursevalues('c006','C#','t003');

insertintocoursevalues('c007','JavaScript','t002');

insertintocoursevalues('c008','DIV+CSS','t001');

insertintocoursevalues('c009','PHP','t003');

insertintocoursevalues('c010','EJB3.0','t002');

commit;

/***************初始化成绩表***********************/

insertintoscvalues('s001','c001',78.9);

insertintoscvalues('s002','c001',80.9);

insertintoscvalues('s003','c001',81.9);

insertintoscvalues('s004','c001',60.9);

insertintoscvalues('s001','c002',82.9);

insertintoscvalues('s002','c002',72.9);

insertintoscvalues('s003','c002',81.9);

insertintoscvalues('s001','c003','59');

commit;

练习:

注意:如下练习中的数据是根据初始化到数据库中的数据来写的SQL语句,请大家务必注意。

1、查询“c001”课程比“c002”课程成绩高的所有学生的学号;

2、查询平均成绩不小于60分的同学的学号和平均成绩;

3、查询所有同学的学号、姓名、选课数、总成绩;

4、查询姓“刘”的老师的个数;

5、查询没学过“谌燕”老师课的同学的学号、姓名;

6、查询学过“c001”并且也学过编号“c002”课程的同学的学号、姓名;

7、查询学过“谌燕”老师所教的所有课的同学的学号、姓名;

8、查询课程编号“c002”的成绩比课程编号“c001”课程低的所有同学的学号、姓名;

9、查询所有课程成绩不不小于60分的同学的学号、姓名;

10、查询没有学全所有课的同学的学号、姓名;

11、查询至少有一门课与学号为“s001”的同学所学相似的同学的学号和姓名;

12、查询至少学过学号为“s001”同学所有一门课的其他同学学号和姓名;

13、把“SC”表中“谌燕”老师教的课的成绩都更改为此课程的平均成绩;

14、查询和“s001”号的同学学习的课程完全相似的其他同学学号和姓名;

15、删除学习“谌燕”老师课的SC表记录;

16、向SC表中插入某些记录,这些记录规定符合如下条件:没有上过编号“c002”课程的同学学号、“c002”号课的平均成绩;

17、查询各科成绩最高和最低的分:以如下形式显示:课程ID,最高分,最低分

18、按各科平均成绩从低到高和及格率的百分数从高到低次序

19、查询不一样老师所教不一样课程平均分从高到低显示

20、记录列印各科成绩,各分数段人数:课程ID,课程名称,[100-85],[85-70],[70-60],[<60]

21、查询各科成绩前三名的记录:(不考虑成绩并列状况)

22、查询每门课程被选修的学生数

23、查询出只选修了一门课程的所有学生的学号和姓名

24、查询男生、女生人数

25、查询姓“张”的学生名单

26、查询同名同性学生名单,并记录同名人数

27、1981年出生的学生名单(注:Student表中Sage列的类型是number)

28、查询每门课程的平均成绩,成果按平均成绩升序排列,平均成绩相似时,按课程号降序排列

29、查询平均成绩不小于85的所有学生的学号、姓名和平均成绩

30、查询课程名称为“数据库”,且分数低于60的学生姓名和分数

31、查询所有学生的选课状况;

32、查询任何一门课程成绩在70分以上的姓名、课程名称和分数;

33、查询不及格的课程,并按课程号从大到小排列

34、查询课程编号为c001且课程成绩在80分以上的学生的学号和姓名;

35、求选了课程的学生人数

36、查询选修“谌燕”老师所讲课程的学生中,成绩最高的学生姓名及其成绩

37、查询各个课程及对应的选修人数

38、查询不一样课程成绩相似的学生的学号、课程号、学生成绩

39、查询每门功课成绩最佳的前两名

40、记录每门课程的学生选修人数(超过10人的课程才记录)。规定输出课程号和选修人数,查询成果按人数降序排列,若人数相似,按课程号升序排列

41、检索至少选修两门课程的学生学号

42、查询所有学生都选修的课程的课程号和课程名

43、查询没学过“谌燕”老师讲授的任一门课程的学生姓名

44、查询两门以上不及格课程的同学的学号及其平均成绩

45、检索“c004”课程分数不不小于60,按分数降序排列的同学学号

46、删除“s002”同学的“c001”课程的成绩

答案:

1.

*********************************

selecta.*from

(select*fromscawhereo='c001')a,

(select*fromscbwhereo='c002')b

wherea.sno=b.snoanda.score>b.score;

*********************************

select*fromsca

whereo='c001'

and

exists(select*fromscbwhereo='c002'anda.score>b.score

anda.sno=b.sno)

*********************************

2.

*********************************

selectsno,avg(score)fromsc

groupbysnohavingavg(score)>60;

*********************************

3.

*********************************

selecta.*,s.snamefrom(selectsno,sum(score),count(cno)fromscgroupbysno)a,studentswherea.sno=s.sno

*********************************

4.

*********************************

selectcount(*)fromteacherwheretnamelike'刘%';

*********************************

5.

*********************************

selecta.sno,a.snamefromstudenta

wherea.sno

notin

(selectdistincts.sno

fromscs,

(selectc.*

fromcoursec,

(selecttno

fromteachert

wheretname='谌燕')t

wherec.tno=t.tno)b

whereo=o)

*********************************

select*fromstudentstwherest.snonotin

(selectdistinctsnofromscsjoincoursecono=o

jointeachertonc.tno=t.tnowheretname='谌燕')

*********************************

6.

*********************************

selectst.*fromsca

joinscbona.sno=b.sno

joinstudentst

onst.sno=a.sno

whereo='c001'ando='c002'andst.sno=a.sno;

*********************************

7.

*********************************

selectst.*fromstudentstjoinscsonst.sno=s.sno

joincoursecono=o

jointeachertonc.tno=t.tno

wheret.tname='谌燕'

*********************************

8.

*********************************

select*fromstudentst

joinscaonst.sno=a.sno

joinscbonst.sno=b.sno

whereo='c002'ando='c001'anda.score<b.score

*********************************

9.

*********************************

selectst.*,s.scorefromstudentst

joinscsonst.sno=s.sno

joincoursecono=o

wheres.score<60

*********************************

10.

*********************************

selectstu.sno,stu.sname,count(o)fromstudentstu

leftjoinsconstu.sno=sc.sno

groupbystu.sno,stu.sname

havingcount(o)<(selectcount(distinctcno)fromcourse)

===================================

select*fromstudentwheresnoin

(selectsnofrom

(selectstu.sno,ofromstudentstu

crossjoincoursec

minus

selectsno,cnofromsc)

)

===================================

*********************************

11.

*********************************

selectst.*fromstudentst,

(selectdistincta.snofrom

(select*fromsc)a,

(select*fromscwheresc.sno='s001')b

whereo=o)h

wherest.sno=h.snoandst.sno<>'s001'

*********************************

12.

*********************************

select*fromsc

leftjoinstudentst

onst.sno=sc.sno

wheresc.sno<>'s001'

andoin

(selectcnofromsc

wheresno='s001')

*********************************

13.

*********************************

updatesccsetscore=(selectavg(c.score)

fromcoursea,teacherb

wherea.tno=b.tno

andb.tname='谌燕'

ando=o

groupbyo)

wherecnoin(

selectcnofromcoursea,teacherb

wherea.tno=b.tno

andb.tname='谌燕')

*********************************

14.

*********************************

select*fromscwheresno<>'s001'

minus

(

select*fromsc

minus

select*fromscwheresno='s001'

)

*********************************

15.

*********************************

deletefromsc

whereoin

(

selectcnofromcoursec

leftjointeacherton

c.tno=t.tno

wheret.tname='谌燕'

)

*********************************

16.

*********************************

insertintosc(sno,cno,score)

selectdistinctst.sno,o,(selectavg(score)fromscwherecno='c002')

fromstudentst,sc

wherenotexists

(select*fromscwherecno='c002'andsc.sno=st.sno)ando='c002';

*********************************

17.

*********************************

selectcno,max(score),min(score)fromscgroupbycno;

*********************************

18.

*********************************

selectcno,avg(score),sum(casewhenscore>=60then1else0end)/count(*)

as及格率

fromscgroupbycno

orderbyavg(score),及格率desc

*********************************

19.

*********************************

selectmax(t.tno),max(t.tname),max(o),max(ame),o,avg(score)fromsc,coursec,teachert

whereo=oandc.tno=t.tno

groupbyo

orderbyavg(score)desc

*********************************

20.

*********************************

selecto,ame,

sum(case

whenscorebetween85and100then1else0end)AS"[100-85]",

sum(case

whenscorebetween70and85then1else0end)AS"[85-70]",

sum(case

whenscorebetween60and70then1else0end)AS"[70-60]",

sum(case

whenscore<60then1else0end)AS"[<60]"

fromsc,coursec

where

o=o

groupbyo,ame;

*********************************

21.

*********************************

select*from

(selectsno,cno,score,row_number()over(partitionbycnoorderbyscoredesc)rnfromsc)

wherern<4

*********************************

22.

*********************************

selectcno,count(sno)fromscgroupbycno;

*********************************

23.

*********************************

selectsc.sno,st.sname,count(cno)fromstudentst

leftjoinsc

onsc.sno=st.sno

groupbyst.sname,sc.snohavingcount(cno)=1;

*********************************

24.

*********************************

selectssex,count(*)fromstudentgroupbyssex;

*********************************

25.

*********************************

select*fromstudentwheresnamelike'张%';

*********************************

26.

*********************************

selectsname,count(*)fromstudentgroupbysnamehavingcount(*)>1;

*********************************

27.

*********************************

selectsno,sname,sage,ssexfromstudenttwhereto_char(sysdate,'yyyy')-sage=1988

*********************************

28.

*********************************

selectcno,avg(score)fromscgroupbycnoorderbyavg(score)asc,cnodesc;

*********************************

29.

*********************************

selectst.sno,st.sname,avg(score)fromstudentst

leftjoinsc

onsc.sno=st.sno

groupbyst.sno,st.snamehavingavg(score)>85;

*********************************

30.

*********************************

selectsname,scorefromstudentst,sc,coursec

wherest.sno=sc.snoando=oandame='Oracle'andsc.score<60

*********************************

31.

*********************************

selectst.sno,st.sname,amefromstudentst,sc,coursec

wheresc.sno=st.snoando=o;

*********************************

32.

*********************************

selectst.sname,ame,sc.scorefromstudentst,sc,coursec

wheresc.sno=st.snoando=oandsc.score>70

*********************************

33.

*********************************

selectsc.sno,ame,sc.scorefromsc,coursec

whereo=oandsc.score<60orderbyodesc;

*********************************

34.

*********************************

selectst.sno,st.sname,sc.scorefromsc,studentst

wheresc.sno=st.snoandcno='c001'andscore>80;

*********************************

35.

*********************************

selectcount(distinctsno)fromsc;

*********************************

36.

*********************************

selectst.sname,scorefromstudentst,sc,coursec,teachert

where

st.sno=sc.snoando=oandc.tno=t.tno

andt.tname='谌燕'andsc.score=

(selectmax(score)fromscwhereo=o)

*********************************

37.

*********************************

selectcno,count(sno)fromscgroupbycno;

*********************************

38.

*********************************

selecta.*fromsca,scbwherea.score=b.scoreando<>o

*********************************

39.

*********************************

select*from(

selectsno,cno,score,row_number()over(partitionbycnoorderbyscoredesc)my_rnfrom

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论