数据库练习参考答案.docx

上传人:b****2 文档编号:17093804 上传时间:2023-07-21 格式:DOCX 页数:9 大小:17.25KB
下载 相关 举报
数据库练习参考答案.docx_第1页
第1页 / 共9页
数据库练习参考答案.docx_第2页
第2页 / 共9页
数据库练习参考答案.docx_第3页
第3页 / 共9页
数据库练习参考答案.docx_第4页
第4页 / 共9页
数据库练习参考答案.docx_第5页
第5页 / 共9页
数据库练习参考答案.docx_第6页
第6页 / 共9页
数据库练习参考答案.docx_第7页
第7页 / 共9页
数据库练习参考答案.docx_第8页
第8页 / 共9页
数据库练习参考答案.docx_第9页
第9页 / 共9页
亲,该文档总共9页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

数据库练习参考答案.docx

《数据库练习参考答案.docx》由会员分享,可在线阅读,更多相关《数据库练习参考答案.docx(9页珍藏版)》请在冰点文库上搜索。

数据库练习参考答案.docx

数据库练习参考答案

根据给出的表结构完成以下题目

表1-1Student表结构

列名说明数据类型约束

Sno学号字符串,长度为7主码

Sname姓名字符串,长度为10非空

Ssex性别字符串,长度为2取‘男’或‘女’

Sage年龄整数取值15~45

Sdept所在系字符串,长度为20默认为‘计算机系’

表3-1Student表数据

SnoSnameSsexSageSdept

9512101李勇男19计算机系

9512102刘晨男20计算机系

9512103王敏女20计算机系

9521101张立男22信息系

9521102吴宾女21信息系

9521103张海男20信息系

9531101钱小平女18数学系

9531102王大力男19数学系

-------------------------------------------------------------------------------------------------------------------

表1-2Course表结构

列名说明数据类型约束

Cno课程号字符串,长度为10主码

Cname课程名字符串,长度为20非空

Ccredit学分整数取值大于0

Semster学期整数取值大于0

Period学时整数取值大于0

表3-2Course表数据

CnoCnameCcreditSemester

C01计算机文化学31

C02VB23

C03计算机网络47

C04数据库基础66

C05高等数学82

C06数据结构54

 

表1-3SC表结构

列名说明数据类型约束

Sno学号字符串,长度为7主码,引用Student的外码

Cno课程名字符串,长度为10主码,引用Course

Grade成绩整数取值0~100

 

表3-3SC表数据

SnoCnoGradeXKLB

9512101c0190必修

9512101c0286选修

9512101c06必修

9512102c0278选修

9512102c0466必修

9521102c0182选修

9521102c0275选修

9521102c0492必修

9521102c0550必修

9521103c0268选修

9521103c06必修

9531101c0180选修

9531101c0595必修

9531102c0585必修

题1:

查询没有选修课程“c01”的学生姓名和所在系。

答案:

selectsname,sdeptfromstudentwheresnonotin(selectsnofromscwherecno='C01')

selectsname,sdeptfromstudent,sc

where(student.sno=sc.sno)and(sc.sno!

=“co1”)

题2:

为SC表添加“选课类别”列,此列的定义为XKLBchar(4)。

答案:

altertablescadd(XKLBvarchar2(4));

题3:

将新添加的XKLB的类型改为char(6)。

答案:

altertablescmodify(XKLBvarchar2(6));

题4:

删除Course表的Period列。

答案:

altertablecoursedropcolumnperiod;

题5:

删除计算机系不及格学生的选课记录。

答案:

deletefromscwheregrade<60andsnoin(selectsnofromstudentwheresdept='计算机系');

题6:

查询全体学生的学号与姓名。

答案:

selectsno,snamefromstudent;

题7:

查询全体学生的姓名,学号和所在系。

答案:

selectsname,sno,sdeptfromstudent;

题8:

查询全体学生的记录。

答案:

select*fromstudent;

题9:

查询全体学生的姓名及其出生年份。

答案:

selectsname,2014-sagefromstudent;

或selectsname,(to_char(sysdate,'YYYY')-sage)fromstudent;

题10:

查询全体学生的姓名和出生年份,比在出生年份列前加入一个列,此列的每行数据均为“YearofBirth”常量值。

答案:

selectsname,'YearofBirth',(to_char(sysdate,'YYYY')-sage)fromstudent;

题11:

在选课表(SC)中查询有哪些学生选修了课程,并列出学生的学号。

答案:

selectdistinctsnofromsc;

题12:

查询计算机系全体学生的姓名。

答案:

selectdistinctsnamefromstudentwheresdept='计算机系';

题13:

查询所有年龄在20岁以下的学生的姓名及年龄。

答案:

selectsname,sagefromstudentwheresage<20;

题14:

查询考试成绩不及格的学生的学号。

答案:

selectdistinctsnofromscwheregrade<60;

题15:

查询年龄在20~23岁之间的学生的姓名,所在系和年龄。

答案:

selectsname,sdept,sagefromstudentwheresage>=20andsage<=23;

题16:

查询年龄不在20~23之间的学生的姓名,所在系和年龄。

答案:

selectsname,sdept,sagefromstudentwheresage<20orsage>23;

题17:

查询信息系,数学系和计算机系学生的姓名和性别。

答案:

selectsname,ssexfromstudentwheresdeptIN(‘信息系’,‘数学系’,‘计算机系’);

题18:

查询既不属于信息系,数学系,也不属于计算机系的学生的姓名和性别。

答案:

selectsname,ssexfromstudentwheresdeptnotin('信息系','数学系','数学系');

题19:

查询姓“张”的学生的详细信息。

答案:

select*fromstudentwheresnamelike‘张%’;

题20:

查询学生表中姓“张”,姓“李”和姓“刘”的学生的情况。

答案:

select*fromstudentwheresnamelike'张%'orsnamelike'李%'orsnamelike'刘%';

或者

select*fromstudentwheresnamelike'[张李刘]%';//错误

题21:

查询名字中第2个字为“小”或“大”字的学生的姓名和学号。

答案:

selectsname,snofromstudentwheresnamelike'_小%'orsnamelike'_大%';

或者

selectsname,snofromstudentwheresnamelike'_[小大]%';

题22:

查询所有不姓“刘”的学生。

答案:

select*fromstudentwheresnamenotlike'刘%';

题23:

从学生表中查询学号的最后一位不是2,3,5的学生的情况。

答案:

select*fromstudentwheresnonotlike'%2'andsnonotlike'%3'andsnonotlike'%5';

或者

select*fromstudentwheresnonotlike'%[235]';//错误

题24:

查询无考试成绩的学生的学号和相应的课程号。

答案:

selectsno,cnofromscwheregradeisnull;

题25:

查询所有有考试成绩的学生的学号和课程号。

答案:

selectsno,cnofromscwheregradeisnotnull;

题26:

查询计算机系年龄在20岁以下的学生的姓名。

答案:

selectsnamefromstudentwheresdept='计算机系'andsage<=20;

题27:

将学生按年龄升序排序。

答案:

select*fromstudentorderbysageasc;

题28:

查询选修了课程“c02”的学生的学号及其成绩,查询结果按成绩降序排列。

答案:

selectsno,gradefromscwherecno='C02'ORDERBYGRADEDESC;

题29:

查询全体学生的信息,查询结果按所在系的系名升序排列,同一系的学生按年龄降序排列。

答案:

select*fromstudentorderbysdept,sageDESC;

题30:

统计学生总人数。

答案:

SELECTCount(*)fromstudent;

题31:

统计选修了课程的学生的人数。

答案:

SELECTcount(distinctsno)fromsc;

题32:

计算学号为9512101的学生的考试总成绩之和。

答案:

selectSUM(GRADE)fromscwhereSNO='9512101';

题33:

计算课程“c01”的学生的考试平均成绩。

答案:

selectavg(GRADE)fromscwherecno='C01';

题34:

查询选修了课程“c01”的学生的最高分和最低分。

答案:

selectMAX(GRADE),MIN(GRADE)fromscwherecno='C01';

题35:

统计每门课程的选课人数,列出课程号和人数。

答案:

selectcno,count(sno)fromscgroupbycno;

题36:

查询每名学生的选课们数和平均成绩。

答案:

SELECTSNO,COUNT(CNO),sum(GRADE)/COUNT(CNO)FROMSCgroupbysno;

题37:

查询选修了3门以上课程的学生的学号。

答案:

selectsno,count(*)fromscgroupbysnohavingcount(*)>3;

题38:

查询选课门数等于或大于4门的学生的平均成绩和选课门数。

答案:

selectsno,avg(Grade),count(*)fromscgroupbysnohavingcount(*)>=4;

题39:

查询每个学生的情况及其选课的情况。

答案:

selectstudent.sno,sname,ssex,sage,o,cn.gradefromstudent,sc

wherestudent.sno=sc.sno;

题40:

去掉例38中的重复列。

答案:

selectdistinctavg(grade),count(sno)选课门数fromscgroupbysnohavingcount(sno)>3;

题41:

查询计算机系学生的选课情况,要求列出学生的名字,所修课的课程号和成绩。

答案:

selectstudent.sname,o,sc.gradefromscleftjoinstudentonstudent.sno=sc.snowheresc.sdept='计算机系';

题42:

查询信息系选修VB课程的学生的成绩,要求列出学生姓名,课程名和成绩。

答案:

selectstudent.sname,o,sc.gradefromstudentjoinsconstudent.sno=sc.snojoincourseono=owheresc.sdept='信息系'andame='VB';

题43:

查询所有选修了VB课程的学生的情况,要求列出学生姓名和所在的系。

答案:

selectstudent.sname,sc.sdeptfromstudentjoinsconstudent.sno=sc.snojoincourseono=owhereame='VB';

题44:

查询与刘晨在同一个系学习的学生的姓名和所在系。

答案:

selects2.sname,s2.sdeptfromstudents1,students2wheres1.dept=s2.deptands1.sname='刘晨'ands2.sname!

='刘晨';

题45:

查询学生的选课情况,包括选修课程的学生和没有修课的学生。

答案:

select*fromstudentleftjoinsconstudent.sno=sc.sno;

题46:

查询与刘晨在同一个系的学生。

答案:

selectsno,snamefromstudentst1,studentst2wherest1.sno=st2.snoandst2.sname='刘晨';

题47:

查询成绩大于90分的学生的学号和姓名。

答案:

selectsno,sname,gradefromstudent,scwheregradein(selectgradefromscwheregrade>90)

题48:

查询选修了“数据库基础”课程的学生的学号和姓名。

答案:

selectsno,snamefromstudentwheresnoin(selectsnofromscwherecnoin(selectcnofromcoursewherecname='数据库基础'))

题49:

查询选修了课程“c02”且成绩高于次课程的平均成绩的学生的学号和成绩。

答案:

selectsno,gradefromscwheregrade>(selectAVG(grade)fromscwherecno='C02'groupbycno)

题50:

查询选修了课程“c01”的学生姓名。

答案:

selectsnamefromstudentwheresnoin(selectsnofromscwherecno='C01')

 

THANKS!

!

!

 

致力为企业和个人提供合同协议,策划案计划书,学习课件等等

打造全网一站式需求

欢迎您的下载,资料仅供参考

 

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 自然科学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2