2018-06-03-oracleTest

Oracle实验练习题

  1. 查询Student表中的所有记录的Sname、Ssex和Class列。

    select sname ,sex,sclass from student;
  2. 查询教师所有的单位即不重复的Depart列。

    select distinct t.depart from teacher t;
  3. 查询Student表的所有记录

    select * from student;
  4. 查询Score表中成绩在60到80之间的所有记录。

    select * from score sc where degree between 60 and 80; 
    select * from score sc where degree >= 60 and degree <= 80; 
  5. 查询Score表中成绩为85,86或88的记录。

    select * from score  where degree in (85,86,88);
    select * from score  where degree = '85' or degree ='86'or degree = '88');
  6. 查询Student表中“95031”班或性别为“女”的同学记录

    select * from student  where sclass ='95031' and ssex= '女';
  7. 以Class降序查询Student表的所有记录。

    select * from student order by sclass desc;
  8. 以Cno升序、Degree降序查询Score表的所有记录

    select * from score sc order by sc.sno asc ,sc.degree desc;
  9. 查询“95031”班的学生人数。

    select s.sclass 总人数 from student s where sclass = '95031';
  10. 查询Score表中的最高分的学生学号和课程号。(子查询或者排序)

    select sc.sno,sc.cno from score sc order by degree desc;
  11. 查询Score表中至少有5名学生选修的并以3开头的课程的平均分数。

    select cno, avg(degree) from score where cno like '3%' group by cno having count(1)>=5 ;
  12. 查询所有学生的Sname、Cno和Degree列

    select s.sname,sc.cno,sc.degree from score sc,student s where sc.sno=s.sno;
  13. 查询所有学生的Sno、Cname和Degree列

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

    select s.sname,t.degree,c.cname from score t,student s,course c where t.sno=s.sno and t.cno =c.cno;
  15. 查询“张旭“教师任课的学生成绩。

    select t.tno,c.cno,c.cname,s.degree from TEACHER t  
    join course c on t.tno =c.tno
    join score s on c.cno =s.cno where t.tname='张旭';    
  16. 查询选修某课程的同学人数多于5人的教师姓名。

    select tname from teacher e 
     join course c on e.tno=c.tno
     join(select cno from SCORE  group by cno having count(cno)>5) t on c.cno=t.cno   ;
  17. 查询和学号为108的同学同年出生的所有学生的Sno、Sname和Sbirthday列。

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

    select cno from SCORE t where degree>85 group by cno
  19. 查询出“计算机系“教师所教课程的成绩表

    select t.sno,t.cno,t.degree from SCORE t 
    join course c on t.cno=c.cno
    join teacher e on c.tno=e.tno where e.depart ='计算机系';
  20. 查询“计算机系”与“电子工程系“不同职称的教师的Tname和Prof

    select tname,prof from teacher where depart ='电子工程系' and prof 
    not in(select prof from teacher where depart ='计算机系')
    or depart ='计算机系' and prof not in(select prof from teacher where depart='电子工程系');
    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 )
    

    作者: 杨校

    出处: https://blog.csdn.net/kese7952

    分享是快乐的,也见证了个人成长历程,文章大多都是工作经验总结以及平时学习积累,基于自身认知不足之处在所难免,也请大家指正,共同进步。

    本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出, 如有问题, 可邮件([email protected])咨询。

猜你喜欢

转载自blog.csdn.net/kese7952/article/details/80558881
今日推荐