zoukankan      html  css  js  c++  java
  • 10-17 Oracle 基础练习

     
     
    --1、查询Student表中的所有记录的Sname、Ssex和Class列。
    select t.sname,t.ssex,t.sclass from student t;
    --2、 查询教师所有的单位即不重复的Depart列。
    select distinct e.depart from teacher e;

    --3、 查询Student表的所有记录。
    select * from student;

    --4、 查询Score表中成绩在60到80之间的所有记录。
    select * from score s where s.degree>60 and s.degree<80;
    select s.degree from score s where s.degree between 60 and 80;

    --5、 查询Score表中成绩为85,86或88的记录。
    select * from score s where s.degree=85 or s.degree=86 or s.degree=88;

    --6、 查询Student表中“95031”班或性别为“女”的同学记录。
    select * from student s where s.ssex='' or s.sclass='95031';

    --7、 以Class降序查询Student表的所有记录。
    select * from student s order by sclass desc;

    --8、 以Cno升序、Degree降序查询Score表的所有记录。
    select *from score order by cno,degree desc;

    --9、 查询“95031”班的学生人数。
    select count(*) from student where sclass='95031';

    --10、 查询Score表中的最高分的学生学号和课程号。(子查询或者排序)
    select sno,cno from score where degree = (select max(degree) from score);
    select * from(select sno,cno from score order by degree desc) where rownum=1;

     

    --11、 查询每门课的平均成绩。
    select cno,avg(degree) from score group by cno;

    --12、查询Score表中至少有5名学生选修的并以3开头的课程的平均分数。
    select cno,avg(degree) from score where cno like '3%' group by cno having count(1)>5;

    --13、查询分数大于70,小于90的Sno列。
    select sno from score where degree between 70 and 90;

    --14、查询所有学生的Sname、Cno和Degree列。
    select t.sname,s.cno,s.degree from student t,score s where t.sno=s.sno;
    select t.sname,s.cno,s.degree from student t join score s on t.sno=s.sno;

    --15、查询所有学生的Sno、Cname和Degree列。
    select t.sno,c.cname,s.degree from student t,course c,score s where s.sno=t.sno and c.cno=s.cno;
    select t.sno,c.cname,s.degree from score s join student t on t.sno=s.sno join course c on c.cno=s.cno;

    --16、查询所有学生的Sname、Cname和Degree列。
    select t.sname,c.cname,s.degree from student t,course c,score s where t.sno=s.sno and c.cno=s.cno;

    --17、 查询“95033”班学生的平均分。
    select avg(degree) from score where sno in(select sno from student where sclass='95033');
    /*
    18、 假设使用如下命令建立了一个grade表:
    create table grade(low  number(3),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’)
    现查询所有同学的Sno、Cno和rank列。*/
    create table grade 
    (
    low number(3),
    upp number(3),
    rank char(2)
    );
    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');
    select s.sno,s.cno,g.rank from score s,grade g where s.degree between g.low and g.upp;

    --19、  查询选修“3-105”课程的成绩高于“109”号同学成绩的所有同学的记录。
    select * from score where cno='3-105'and degree>(select degree from score where sno='109'and cno='3-105');

    --20、查询score中选学多门课程的同学中分数为非最高分成绩的记录。
    select * from score where degree not in(select max(degree) from score group by sno having count(2)>1);

    --21、 查询成绩高于学号为“109”、课程号为“3-105”的成绩的所有记录。
    select * from score where cno='3-105'and degree>(select degree from score where sno='109' and cno='3-105');

    --22、查询和学号为108的同学同年出生的所有学生的Sno、Sname和Sbirthday列。
    select * from student  where to_char(sbirthday,'yyyy')=(select to_char(t.sbirthday,'yyyy') from student t where sno='108');

    --23、查询“张旭“教师任课的学生成绩。
    select degree from course c join teacher t on c.tno=t.tno join score s on c.cno= s.cno where t.tname='张旭';

    --24、查询选修某课程的同学人数多于5人的教师姓名。
    select tname from teacher t where tno in
    (select tno from course where cno in
    (select s.cno from score s group by s.cno having count(1)>5));

    --25、查询95033班和95031班全体学生的记录。
    select * from student t join score s on t.sno=s.sno join course c on c.cno=s.cno
    where sclass='95033'or sclass='95031';

    --26、 查询存在有85分以上成绩的课程Cno.
    select cno,cname from course where cno in(select cno from score where degree>85);

     

    --27、查询出“计算机系“教师所教课程的成绩表。
    select degree from score s join course c on s.cno=c.cno join teacher t on c.tno=t.tno where  depart='计算机系';

    --28、查询“计算机系”与“电子工程系“不同职称的教师的Tname和Prof。
    select tname,prof from teacher where prof not in
     (select a.prof from (select prof from teacher where depart='计算机系')a
    join (select prof from teacher where depart='电子工程系') b 
    on a.prof=b.prof)and depart in('计算机系','电子工程系');

    --29、查询选修编号为“3-105“课程且成绩至少高于选修编号为“3-245”的同学的Cno、Sno和Degree,并按Degree从高到低次序排序。
    select cno,sno,degree from score where cno='3-105' and degree>=(select max(degree) from score where cno='3-245')order by degree desc;

    --30、查询选修编号为“3-105”且成绩高于选修编号为“3-245”课程的同学的Cno、Sno和Degree.
    select cno,sno,degree from score where cno='3-105' and degree>=(select max(degree) from score where cno='3-245');

     

    --31、查询所有教师和同学的name、sex和birthday.
    select tname,tsex,tbirthday from teacher
    union all select t.sname,t.ssex,t.sbirthday from student t;

    --32、查询所有“女”教师和“女”同学的name、sex和birthday.
    select tname,tsex,tbirthday from teacher where tsex=''
    union all select t.sname,t.ssex,t.sbirthday from student t where t.ssex='';

  • 相关阅读:
    把Windows装进U盘
    Java 潜拷贝和深拷贝(浅复制和深复制)
    《远大前程——从软件新手到行业大牛》读书笔记
    解决windows8 metro应用不能联网
    [转载]schtasks命令使用实例介绍
    程序员网址
    VS2008,vs2010 快捷键大全 转载
    题解:2018级算法第一次练习赛 妙妙趣排序
    题解:2018级算法第一次上机 C1pair
    #编译原理# 词法分析(三)第二部分
  • 原文地址:https://www.cnblogs.com/dandan1224/p/5951476.html
Copyright © 2011-2022 走看看