📣📣📣📣本系列的文章:
提供Oracle经典基础练习题及答案,适合正在学习Oracle的小程序员们进来练习哦~~😊😊
今天分享的还是Oracle基础练习题💖💖~~
文章热度高的话会持续更新哦💖💖~~
关注【小阿飞_】 带你遨游题海😜
就是喜欢看你们刷题😜
题目:
📝 查询Student表中的所有记录的Sname、Ssex和Class列
📝查询Student表中“95031”班或性别为“女”的同学记录
📝查询Score表中 至少有5名学生选修 的并以3开头的课程 的平均分数
📝假设使用如下命令建立了一个grade成绩表并查询所有同学的Sno、Cno和rank列
📝查询 选修“3-105”课程的成绩 高于“109”号同学成绩 的所有同学的记录
📝查询 score中选学一门以上课程 的同学中 分数为非最高分成绩的记录
📝查询和 学号为108的同学 同年出生的 所有学生的Sno、Sname和Sbirthday
💬小提示: 在Oracle中使用如下建表语句和数据插入语句,以完成相关练习题📝
建表语句:
CREATE TABLE STUDENT ----学生表
(SNO VARCHAR2(3) NOT NULL,
SNAME VARCHAR2(4) NOT NULL,
SSEX VARCHAR2(2) NOT NULL,
SBIRTHDAY DATE,
CLASS VARCHAR2(5))
CREATE TABLE COURSE ---- 课程表
(CNO VARCHAR2(5) NOT NULL,
CNAME VARCHAR2(10) NOT NULL,
TNO VARCHAR2(10) NOT NULL)
CREATE TABLE SCORE -----分数表
(SNO VARCHAR2(3) NOT NULL,
CNO VARCHAR2(5) NOT NULL,
DEGREE NUMERIC(10, 1) NOT NULL)
CREATE TABLE TEACHER ---------教师表
(TNO VARCHAR2(3) NOT NULL,
TNAME VARCHAR2(4) NOT NULL, TSEX VARCHAR2(2) NOT NULL,
TBIRTHDAY DATE NOT NULL, PROF VARCHAR2(6),
DEPART VARCHAR2(10) NOT NULL)
插入语句:
INSERT INTO STUDENT (SNO,SNAME,SSEX,SBIRTHDAY,CLASS) VALUES (108 ,'曾华' ,'男' ,TO_DATE('2011-2-24 ','YYYY-MM-DD'),95033);
INSERT INTO STUDENT (SNO,SNAME,SSEX,SBIRTHDAY,CLASS) VALUES (105 ,'匡明' ,'男' ,TO_DATE('1975-10-02 ','YYYY-MM-DD'),95031);
INSERT INTO STUDENT (SNO,SNAME,SSEX,SBIRTHDAY,CLASS) VALUES (107 ,'王丽' ,'女' ,TO_DATE('1976-01-23','YYYY-MM-DD'),95033);
INSERT INTO STUDENT (SNO,SNAME,SSEX,SBIRTHDAY,CLASS) VALUES (101 ,'李军' ,'男' ,TO_DATE('1976-02-20','YYYY-MM-DD'),95033);
INSERT INTO STUDENT (SNO,SNAME,SSEX,SBIRTHDAY,CLASS) VALUES (109 ,'王芳' ,'女' ,TO_DATE('1976-02-20','YYYY-MM-DD'),95031);
INSERT INTO STUDENT (SNO,SNAME,SSEX,SBIRTHDAY,CLASS) VALUES (103 ,'陆君' ,'男' ,TO_DATE('1974-06-03','YYYY-MM-DD'),95031);
INSERT INTO COURSE(CNO,CNAME,TNO)VALUES ('3-105' ,'计算机导论',825);
INSERT INTO COURSE(CNO,CNAME,TNO)VALUES ('3-245' ,'操作系统' ,804);
INSERT INTO COURSE(CNO,CNAME,TNO)VALUES ('6-166' ,'数据电路' ,856);
INSERT INTO COURSE(CNO,CNAME,TNO)VALUES ('9-888' ,'高等数学' ,100);
INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (103,'3-245',86);
INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (105,'3-245',75);
INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (109,'3-245',68);
INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (103,'3-105',92);
INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (105,'3-105',88);
INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (109,'3-105',76);
INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (101,'3-105',64);
INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (107,'3-105',91);
INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (108,'3-105',78);
INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (101,'6-166',85);
INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (107,'6-106',79);
INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (108,'6-166',81);
INSERT INTO TEACHER(TNO,TNAME,TSEX,TBIRTHDAY,PROF,DEPART)
VALUES (804,'李诚','男',TO_DATE('1977-08-14','YYYY-MM-DD'),'副教授','计算机系');
INSERT INTO TEACHER(TNO,TNAME,TSEX,TBIRTHDAY,PROF,DEPART)
VALUES (856,'张旭','男',TO_DATE('1969-03-12','YYYY-MM-DD'),'讲师','电子工程系');
INSERT INTO TEACHER(TNO,TNAME,TSEX,TBIRTHDAY,PROF,DEPART)
VALUES (825,'王萍','女',TO_DATE('1972-05-05','YYYY-MM-DD'),'助教','计算机系');
INSERT INTO TEACHER(TNO,TNAME,TSEX,TBIRTHDAY,PROF,DEPART)
VALUES (831,'刘冰','女',TO_DATE('1977-08-14','YYYY-MM-DD'),'助教','电子工程系');
💬小提示:
💬 以上建表语句创建的表和插入的数据对应了45道Oracle数据库经典练习题,由于篇幅有限,几天小程序员们先做20道😜
📣 题目难度是一道道逐渐增加的,所以下期文章的题目难度会加大,欢迎来挑战!
😊 在数据库语句中,每一道题目的写法可能不止一种,不论sql语句写的是什么,只要能查询出符合题目要求的数据,就是正确且成功的答案哦💖💖
答案:
-
📝 查询Student表中的所有记录的Sname、Ssex和Class列
select Sname,Ssex,Class from Student;
-
📝 查询教师所有的单位即不重复的Depart列
select distinct Depart from TEACHER;
-
📝查询Score表中成绩在60到80之间的所有记录
select * from Score where DEGREE>60 and DEGREE<80;
-
📝查询Score表中成绩为85,86或88的记录
select * from Score where DEGREE in(85,86,88);
-
📝查询Student表中“95031”班或性别为“女”的同学记录
select * from STUDENT where CLASS='95031' or Ssex='女';
-
📝以Class降序查询Student表的所有记录
select * from STUDENT order by Class desc;
-
📝以Cno升序、Degree降序查询Score表的所有记录
select * from Score order by Degree desc,Cno asc;
-
📝查询“95031”班的学生人数
select count(sno) from STUDENT where class=95031;
-
📝查询Score表中的最高分的学生学号和课程号
select a.*,rownum from ( select score.*,rownum from score order by degree desc )a where rownum=1; --这样查询也行哦: select a.*,rownum from( select * from score order by degree desc )a where rownum=1;
-
📝查询‘3-105’号课程的平均分
select avg(degree) from score where Cno='3-105';
-
📝查询Score表中 至少有5名学生选修 的并以3开头的课程 的平均分数
select avg(degree) from score where Cno like '3%' group by cno having count(cno)>5;--边分组边计数
-
📝查询最低分大于70,最高分小于90的Sno列
select sno from SCORE where degree between 70 and 90;
-
📝查询所有学生的Sname、Cno和Degree列
select a.Sname,b.Cno,b.Degree from student a,score b where a.sno=b.sno;
-
📝查询所有学生的Sno、Cname和Degree列
select a.sno,b.cname,c.Degree from student a,course b,score c where a.sno=c.sno and c.cno=b.cno;
-
📝查询所有学生的Sname、Cname和Degree列
select a.sno,b.cname,c.Degree from student a,course b,score c where a.sno=c.sno and c.cno=b.cno;
-
📝查询“95033”班所选课程的平均分
select avg(degree) from score a,student b where a.sno=b.sno and b.class='95033' group by a.degree;
-
📝假设使用如下命令建立了一个grade成绩表并查询所有同学的Sno、Cno和rank列
create table grade(low number(3,0),upp number(3),rank char(1)); insert into grade values(90,100,'A'); insert into grade values(80,89,'B'); insert into grade values(70,79,'C'); insert into grade values(60,69,'D'); insert into grade values(0,59,'E'); commit;
select a.Sno,b.Cno,c.rank from student a,score b,grade c where a.sno=b.sno;
-
📝查询 选修“3-105”课程的成绩 高于“109”号同学成绩 的所有同学的记录
select * from score where cno='3-105'and degree>( select degree from score where sno=109 and cno='3-105' );
-
📝查询 score中选学一门以上课程 的同学中 分数为非最高分成绩的记录
select sno,min(degree) from score group by sno having count(sno)>1;
-
📝查询和 学号为108的同学 同年出生的 所有学生的Sno、Sname和Sbirthday列
select Sno,Sname,Sbirthday from student where substr2(Sbirthday,0,4) =( select substr2(Sbirthday(Sbirthday,0,4) from student where sno=107 );
码字不易,点个赞呗😊