50道数据库练习题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
select * from Student;
select * from Course;
select * from Teacher;
select * from SC;
create table Student(S# varchar2(10),Sname varchar2(10),Sage date,Ssex varchar2(10)); commit;
insert into Student values('01' , '赵雷' , to_date('1990-01-01','yyyy-mm-dd') , '男'); insert into Student values('02' , '钱电' , to_date('1990-12-21','yyyy-mm-dd') , '男'); insert into Student values('03' , '孙风' , to_date('1990-05-20','yyyy-mm-dd') , '男'); insert into Student values('04' , '李云' , to_date('1990-08-06','yyyy-mm-dd') , '男'); insert into Student values('05' , '周梅' , to_date('1991-12-01','yyyy-mm-dd') , '女'); insert into Student values('06' , '吴兰' , to_date('1992-03-01','yyyy-mm-dd') , '女'); insert into Student values('07' , '郑竹' , to_date('1989-07-01','yyyy-mm-dd') , '女'); insert into Student values('08' , '王菊' , to_date('1990-01-20','yyyy-mm-dd') , '女'); commit;
create table Course(C# varchar2(10),Cname varchar2(10),T# varchar2(10));
insert into Course values('01' , '语文' , '02');
insert into Course values('02' , '数学' , '01');
insert into Course values('03' , '英语' , '03');
create table Teacher(T# varchar2(10),Tname varchar2(10));
insert into Teacher values('01' , '张三');
insert into Teacher values('02' , '李四');
insert into Teacher values('03' , '王五');
create table SC(S# varchar2(10),C# varchar2(10),score number(4,1))
insert into SC values('01' , '01' , 80);
insert into SC values('01' , '02' , 90);
insert into SC values('01' , '03' , 99);
insert into SC values('02' , '01' , 70);
insert into SC values('02' , '02' , 60);
insert into SC values('02' , '03' , 80);
insert into SC values('03' , '01' , 80);
insert into SC values('03' , '02' , 80);
insert into SC values('03' , '03' , 80);
insert into SC values('04' , '01' , 50);
insert into SC values('04' , '02' , 30);
insert into SC values('04' , '03' , 20);
insert into SC values('05' , '01' , 76);
insert into SC values('05' , '02' , 87);
insert into SC values('06' , '01' , 31);
insert into SC values('06' , '03' , 34);
insert into SC values('07' , '02' , 89);
insert into SC values('07' , '03' , 98);
--1、查询"01"课程比"02"课程成绩高的学生的信息及课程分数
select a.*,b.score,c.score from student a,sc b,sc c where a.s#=b.s# and a.s#=c.s# and b.c#='01'and c.c#='02'and b.score>c.score;
commit;
--2、查询"01"课程比"02"课程成绩低的学生的信息及课程分数
select a.*,b.score,c.score from student a,sc b,sc c where a.s#=b.s# and a.s#=c.s# and b.c#='01'and c.c#='02'and b.score commit; --3、查询平均成绩大于等于60分的同学的学生编号和学生姓名和平均成绩 select a.s#,a.sname,avg(b.score) from student a,sc b where a.s#=b.s# group by a.s#,a.sname having avg(b.score)>=60 ; commit; --4、查询平均成绩小于60分的同学的学生编号和学生姓名和平均成绩 select a.s#,a.sname,avg(b.score) from student a,sc b where a.s#=b.s# group by a.s#,a.sname having avg(b.score)<60 ; commit; --5、查询所有同学的学生编号、学生姓名、选课总数、所有课程的总成绩, 并将结果以每页5组数据的形式分页显示。 select s# as 学生编号,sname as 学生姓名,n1 as 选课总数,n2 as 所有课程总成绩from (select rownum as rn,t.* from( select t.s#,t.sname, count(a.c#) as n1,sum(a.score)as n2 from student t,sc a where t.s#=a.s# group by t.s#,t.sname)t where rownum<=5) where rn>0; commit; --6、查询"李"姓老师的数量 select count(*) from teacher where tname like '李%'; commit; --7、查询学过"张三"老师授课的同学的信息 select t.* from student t where t.s# in (select a.s# from sc a where a.c#='02'); commit;