概述
oracle 深入函数和逻辑思维挑战
create table student(sno varchar2(10) primary key, --学生编号sname varchar2(20), --学生姓名sage number(2), --年龄ssex varchar2(5) --性别);create table teacher(tno varchar2(10) primary key, --教师编号tname varchar2(20) --教师姓名);create table courses(cno varchar2(10), --课程表编号cname varchar2(20), --课程表名称tno varchar2(20), --外键关联teacher表主键constraint pk_course primary key (cno,tno));create table sc(sno varchar2(10), --成绩表编号cno varchar2(10), --外键关联course表主键score number(4,2), --成绩constraint pk_sc primary key (sno,cno));/初始化学生表的数据/insert into student values (‘s001’,‘张三’,23,‘男’);insert into student values (‘s002’,‘李四’,23,‘男’);insert into student values (‘s003’,‘吴鹏’,25,‘男’);insert into student values (‘s004’,‘琴沁’,20,‘女’);insert into student values (‘s005’,‘王丽’,20,‘女’);insert into student values (‘s006’,‘李波’,21,‘男’);insert into student values (‘s007’,‘刘玉’,21,‘男’);insert into student values (‘s008’,‘萧蓉’,21,‘女’);insert into student values (‘s009’,‘陈萧晓’,23,‘女’);insert into student values (‘s010’,‘陈美’,22,‘女’);commit;/初始化教师表****/insert into teacher values (‘t001’, ‘刘阳’);insert into teacher values (‘t002’, ‘谌燕’);insert into teacher values (‘t003’, ‘胡明星’);commit;/初始化课程表*************/insert into courses values (‘c001’,‘J2SE’,‘t002’);insert into course values (‘c002’,‘Java Web’,‘t002’);insert into course values (‘c003’,‘SSH’,‘t001’);insert into course values (‘c004’,‘Oracle’,‘t001’);insert into course values (‘c005’,‘SQL SERVER 2005’,‘t003’);insert into course values (‘c006’,‘C#’,‘t003’);insert into course values (‘c007’,‘JavaScript’,‘t002’);insert into course values (‘c008’,‘DIV+CSS’,‘t001’);insert into course values (‘c009’,‘PHP’,‘t003’);insert into course values (‘c010’,‘EJB3.0’,‘t002’);commit;/初始化成绩表********/insert into sc values (‘s001’,‘c001’,78.9);insert into sc values (‘s002’,‘c001’,80.9);insert into sc values (‘s003’,‘c001’,81.9);insert into sc values (‘s004’,‘c001’,60.9);insert into sc values (‘s001’,‘c002’,82.9);insert into sc values (‘s002’,‘c002’,72.9);insert into sc values (‘s003’,‘c002’,81.9);insert into sc values (‘s001’,‘c003’,‘59’);commit;
先建表和加数据
题目:
1、查询“c001”课程比“c002”课程成绩高的所有学生的学号(知识点:子查询);select * from student s where (select score from sc where cno=‘c001’ and sno=s.sno)>(select score from sc where cno=‘c002’ and sno=s.sno)
2、查询平均成绩大于60 分的同学的学号和平均成绩(知识点:group having);select sno,sum(score) from sc group by sno having sum(score)>60
3、查询所有同学的学号、姓名、选课数、总成绩(知识点:group);select sno,sname,(select sum(score) from sc where sc.sno=s.sno group by sc.sno),(select count() from sc where sc.sno=s.sno group by sc.sno) from student s
4、查询姓“刘”的老师的个数(知识点:like);select count() from teacher where tname like ‘刘%’
5、查询没学过“谌燕”老师课的同学的学号、姓名(知识点:子查询);select sno,sname from student swhere snonot in(select sno from sc where cno in(select cno from courses where tno=(select tno from teacher where tname=‘谌燕’)) group by sno)
6、查询学过“c001”并且也学过编号“c002”课程的同学的学号、姓名(知识点:多表联查);select sno,sname from student swhere ‘c001’ in(select cno from sc where sno=s.sno group by cno)and’c002’ in (select cno from sc where sno=s.sno group by cno)
7、查询学过“谌燕”老师所教课的同学的学号、姓名;(知识点:多表联查)select sno,sname from student swhere snoin(select sno from sc where cno in(select cno from courses where tno=(select tno from teacher where tname=‘谌燕’)) group by sno)
8、查询所有课程成绩小于60 分的同学的学号、姓名;(知识点:多表联查);select sno,sname from student where sno in(select sc.sno from sc,(select row_number() over(partition by sno order by score desc) num,sno,score from sc) s where s.score<60 and s.num=1)
9、查询没有学全所有课的同学的学号、姓名;(知识点:多表联查、group having、子查询);select s.sno,s.SNAME from student s,(select sno,count(cno) from sc group by sno having count(cno)=(select count(*) from courses)) awhere s.sno=a.sno
反正我觉得还是有点挑战的就这几个题目也差不多做了我一个小时,可以挑战一下
最后
以上就是迷人小鸽子为你收集整理的2020-10-22的全部内容,希望文章能够帮你解决2020-10-22所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复