没有合适的资源?快使用搜索试试~ 我知道了~
Oracle Database,又名Oracle RDBMS,或简称Oracle。是甲骨文公司的一款关系数据库管理系统。它是在数据库领域一直处于领先地位的产品。可以说Oracle数据库系统是目前世界上流行的关系数据库管理系统,系统可移植性好、使用方便、功能强,适用于各类大、中、小、微机环境。它是一种高效率、可靠性好的 适应高吞吐量的数据库解决方案。
资源推荐
资源详情
资源评论
oracle 数据库增删改查练习50例-答案
一、建表
--学生表
drop table student;
create table student (sno varchar2(10),sname varchar2(10),sage date,ssex varchar2(10));
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'),'女');
--课程表
drop table course;
create table course (cno varchar2(10),cname varchar2(10),tno varchar2(10));
insert into course values ('01','语文','02');
insert into course values ('02','数学','01');
insert into course values ('03','英语','03');
--教师表
drop table teacher;
create table teacher (tno varchar2(10),tname varchar2(10));
insert into teacher values('01','张三');
insert into teacher values('02','李四');
insert into teacher values('03','王五');
--成绩表
drop table sc;
create table sc (sno varchar2(10),cno varchar2(10),score number(18,1));
insert into sc values('01','01',80.0);
insert into sc values('01','02',90.0);
insert into sc values('01','03',99.0);
insert into sc values('02','01',70.0);
insert into sc values('02','02',60.0);
insert into sc values('02','03',80.0);
insert into sc values('03','01',80.0);
insert into sc values('03','02',80.0);
insert into sc values('03','03',80.0);
insert into sc values('04','01',50.0);
insert into sc values('04','02',30.0);
insert into sc values('04','03',20.0);
insert into sc values('05','01',76.0);
insert into sc values('05','02',87.0);
insert into sc values('06','01',31.0);
insert into sc values('06','03',34.0);
insert into sc values('07','02',89.0);
insert into sc values('07','03',98.0);
commit;
二、查询
1.1、查询同时存在"01"课程和"02"课程的情况
select s.sno, s.sname, s.sage, s.ssex, sc1.score, sc2.score
from student s, sc sc1, sc sc2
where s.sno = sc1.sno
and s.sno = sc2.sno
and sc1.cno = '01'
and sc2.cno = '02';
1.2、查询必须存在"01"课程,"02"课程可以没有的情况
select t.*, s.score_01, s.score_02
from student t
inner join (select a.sno, a.score score_01, b.score score_02
from sc a
left join (select * from sc where cno = '02') b
on (a.sno = b.sno)
where a.cno = '01') s
on (t.sno = s.sno);
2.1、查询同时'01'课程比'02'课程分数低的数据
select s.sno, s.sname, s.sage, s.ssex, sc1.score, sc2.score
from student s, sc sc1, sc sc2
where s.sno = sc1.sno
and s.sno = sc2.sno
and sc1.cno = '01'
and sc2.cno = '02'
and sc1.score < sc2.score;
2.2、查询同时'01'课程比'02'课程分数低或'01'缺考的数据
select s.sno, s.sname, s.sage, s.ssex, t.score_01, t.score_02
from student s,
(select b.sno, a.score score_01, b.score score_02
from (select * from sc where cno = '01') a,
(select * from sc where cno = '02') b
where a.sno(+) = b.sno) t
where s.sno = t.sno
and (t.score_01 < t.score_02 or t.score_01 is null);
3、查询平均成绩大于等于60分的同学的学生编号和学生姓名和平均成绩
select s.sno, s.sname, t.avg_score avg_score
from student s,
(select sno, round(avg(score), 2) avg_score
from sc
group by sno
having avg(score) >= 60
order by sno) t
where s.sno = t.sno;
4、查询平均成绩小于60分的同学的学生编号和学生姓名和平均成绩
4.1、有考试成绩,且小于60分
select s.sno, s.sname, t.avg_score avg_score
from student s,
(select sno, round(avg(score), 2) avg_score
from sc
group by sno
having avg(score) < 60
order by sno) t
where s.sno = t.sno;
4.2、包括没有考试成绩的数据
select g.*
from (select s.sno, s.sname, nvl(t.avg_score, 0) avg_score
from student s,
(select sno, round(avg(score), 2) avg_score
from sc
group by sno
order by sno) t
where s.sno = t.sno(+)) g
where g.avg_score < 60;
5、查询所有同学的学生编号、学生姓名、选课总数、所有课程的总成绩
5.1、查询所有成绩的(不含缺考的)。
select s.sno,s.sname,c.count_cno,c.sum_score
from student s,
(select sno,count(cno) count_cno,sum(score) sum_score from sc group by sno order by sno) c
where s.sno = c.sno
5.2、查询所有成绩的(包括缺考的)。
select a.s_sno, a.s_sname, nvl(a.c_cno, 0), a.s_score
from (select s.sno s_sno,
s.sname s_sname,
c.count_cno c_cno,
c.sum_score s_score
from student s,
(select sno, count(cno) count_cno, sum(score) sum_score
from sc
group by sno
order by sno) c
where s.sno = c.sno(+)) a
6、查询"李"姓老师的数量 (有几个老师姓李)
select count(tn)
from (select tno, substr(tname, 0, 1) tn
from teacher
where substr(tname, 0, 1) = '李') a;
7、哪些学生上过张三(老师)的课
select st.*
from student st, course co, teacher te, sc
where te.tno = co.tno
and co.cno = sc.cno
and sc.sno = st.sno
and te.tname = '张三'
8、哪些学生没上过张三(老师)的课
select *
from student
minus
select st.*
from student st, course co, teacher te, sc
where te.tno = co.tno
and co.cno = sc.cno
and sc.sno = st.sno
and te.tname = '张三'
9、查询 '01' '02'都学过的同学的信息
select st.*
from student st,
(select * from sc where cno = '01') a,
(select * from sc where cno = '02') b
where st.sno = a.sno
and st.sno = b.sno
10、查询学过编号为'01'但是没有学过编号为'02'的课程的同学的信息
select st.*
from student st,
((select sno from sc where cno = '01') minus
(select sno from sc where cno = '02')) a
where st.sno = a.sno;
11、查询没有学全所有课程的同学的信息
11.1 学完所有课程的
select st.*
from student st,
(select sno, count(cno) from sc group by sno having count(cno) = 3) a
where st.sno = a.sno;
11.2 没有学完所有课程的
select st.*
from student st,
剩余14页未读,继续阅读
资源评论
lct_81
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 白色创意风格的时尚化妆美容整站网站源码下载.zip
- 白色创意风格的生活方式企业网站源码下载.zip
- 白色创意风格的时间轴相册模板下载.zip
- 白色创意风格的透视设计源码下载.zip
- 白色创意风格的图片浏览源码下载.zip
- 白色创意风格的室内装修设计CSS3模板.zip
- 白色创意风格的图片排列展示源码下载.rar
- 白色创意风格的图像照片展示企业网站模板.rar
- 白色创意风格的图片相册展示模板下载.rar
- 白色纯净风格的音乐网站模板下载.zip
- 白色纯净的商务博客网站模板下载.zip
- 白色创意风格的用户信息登记源码下载.zip
- 白色大气的服装鞋包商城整站网站模板下载.zip
- 白色纯净简洁的瀑布式企业网站模板下载.zip
- 白色大气的旅游度假酒店企业网站模板下载.zip
- 白色大气风的婚纱摄影网站模板下载.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功