• 3.Oracle学习笔记(45道练习题目)


    The best of  the best

    前言:要理解,而不是死记硬背

    相关的英文单词:

    descending order 降序 :desc

    ascending order 升序   :asc

    Bubble sort 冒泡排序

     

    第一步:导入表

    第二步:开始输入指令

     

    CREATE TABLE STUDENT               
    (SNO VARCHAR(6) NOT NULL,
       SNAME VARCHAR(6) NOT NULL,
       SSEX VARCHAR(6) NOT NULL,
       SBIRTHDAY DATE,
       CLASS VARCHAR(6))
    go
    CREATE TABLE COURSE                
    (CNO VARCHAR(5) NOT NULL,
       CNAME VARCHAR(15) NOT NULL,
       TNO VARCHAR(15) NOT NULL)
    go
    CREATE TABLE SCORE              
    (SNO VARCHAR(3) NOT NULL,
       CNO VARCHAR(5) NOT NULL,
       DEGREE NUMERIC(10, 1) NOT NULL)
    go
    CREATE TABLE TEACHER             
    (TNO VARCHAR(3) NOT NULL,
       TNAME VARCHAR(6) NOT NULL, TSEX VARCHAR(3) NOT NULL,
       TBIRTHDAY DATE NOT NULL, PROF VARCHAR(6),
       DEPART VARCHAR(15) NOT NULL)
    
    
    INSERT INTO STUDENT (SNO,SNAME,SSEX,SBIRTHDAY,CLASS) VALUES (108 ,'曾华' ,'' ,TO_DATE('2011-2-24 ','YYYY-MM-DD'),95033);
    INSERT INTO STUDENT (SNO,SNAME,SSEX,SBIRTHDAY,CLASS) VALUES (105 ,'匡明' ,'' ,TO_DATE('1975-10-02 ','YYYY-MM-DD'),95031);
    INSERT INTO STUDENT (SNO,SNAME,SSEX,SBIRTHDAY,CLASS) VALUES (107 ,'王丽' ,'' ,TO_DATE('1976-01-23','YYYY-MM-DD'),95033);
    INSERT INTO STUDENT (SNO,SNAME,SSEX,SBIRTHDAY,CLASS) VALUES (101 ,'李军' ,'' ,TO_DATE('1976-02-20','YYYY-MM-DD'),95033);
    INSERT INTO STUDENT (SNO,SNAME,SSEX,SBIRTHDAY,CLASS) VALUES (109 ,'王芳' ,'' ,TO_DATE('1976-02-20','YYYY-MM-DD'),95031);
    INSERT INTO STUDENT (SNO,SNAME,SSEX,SBIRTHDAY,CLASS) VALUES (103 ,'陆君' ,'' ,TO_DATE('1974-06-03','YYYY-MM-DD'),95031);
    GO
    INSERT INTO COURSE(CNO,CNAME,TNO)VALUES ('3-105' ,'计算机导论',825);
    INSERT INTO COURSE(CNO,CNAME,TNO)VALUES ('3-245' ,'操作系统' ,804);
    INSERT INTO COURSE(CNO,CNAME,TNO)VALUES ('6-166' ,'数据电路' ,856);
    INSERT INTO COURSE(CNO,CNAME,TNO)VALUES ('9-888' ,'高等数学' ,100);
    GO
    INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (103,'3-245',86);
    INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (105,'3-245',75);
    INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (109,'3-245',68);
    INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (103,'3-105',92);
    INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (105,'3-105',88);
    INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (109,'3-105',76);
    INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (101,'3-105',64);
    INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (107,'3-105',91);
    INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (108,'3-105',78);
    INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (101,'6-166',85);
    INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (107,'6-106',79);
    INSERT INTO SCORE(SNO,CNO,DEGREE)VALUES (108,'6-166',81);
    GO
    INSERT INTO TEACHER(TNO,TNAME,TSEX,TBIRTHDAY,PROF,DEPART)
    VALUES (804,'李诚','',TO_DATE('1977-08-14','YYYY-MM-DD'),'副教授','计算机系');
    
    INSERT INTO TEACHER(TNO,TNAME,TSEX,TBIRTHDAY,PROF,DEPART)
    VALUES (856,'张旭','',TO_DATE('1969-03-12','YYYY-MM-DD'),'讲师','电子工程系');
    INSERT INTO TEACHER(TNO,TNAME,TSEX,TBIRTHDAY,PROF,DEPART)
    VALUES (825,'王萍','',TO_DATE('1972-05-05','YYYY-MM-DD'),'助教','计算机系');
    INSERT INTO TEACHER(TNO,TNAME,TSEX,TBIRTHDAY,PROF,DEPART)
    VALUES (831,'刘冰','',TO_DATE('1977-08-14','YYYY-MM-DD'),'助教','电子工程系');

     

     

    下面是45道题目:

    1、 查询Student表中的所有记录的Sname、Ssex和Class列。
    select sname,ssex,class from student;
    2、 查询教师所有的单位即不重复的Depart列。
    select distinct depart from teacher;
    select distinct(depart) from teacher;
    3、 查询Student表的所有记录。
    select * from student;
    4、 查询Score表中成绩在60到80之间的所有记录。
    select * from score where degree>=60 and degree <=80;
    5、 查询Score表中成绩为85,86或88的记录。
    select * from score where degree=85 or degree=86 or degree =88;
    6、 查询Student表中“95031”班或性别为“女”的同学记录。
    select * from student where class=95031 or ssex ='';
    7、 以Class降序查询Student表的所有记录。
    select * from student order by class desc;
    8、 以Cno升序、Degree降序查询Score表的所有记录。
    select * from score order by cno asc,degree desc;
    9、 查询“95031”班的学生人数。
    select count(sno) from student where class='95031';
    10、查询Score表中的最高分的学生学号和课程号。
    select sno,cno,degree from score where degree=(select max(degree) from score);
    select sno,cno,degree from (select * from score order by degree desc) where rownum=1;
    11、查询‘3-105’号课程的平均分。
    select avg(degree) from score where cno='3-105';
    12、查询Score表中  至少有5名学生选修   的并以   3开头的课程    的平均分数。
    select   *  from  score ;
    select * from score where cno like '3%'  ;
    select cno,count(cno) from score group by cno having count(cno)>5;
    select cno,count(cno),avg(degree) from score where cno like'3%' group by cno having count(cno)>5; select avg(degree) from score where cno like '3%' group by cno having count(cno) > 5; select cno,count(*),avg(degree) from score where cno like '3%' group by cno having count(*)>5 ;

     

  • 相关阅读:
    前端 jquery获取当前页面的URL信息
    PHP合并数组及去重,PHP检测一个数组中有几个相同的
    ThinkPHP缓存技术(S(),F(),查询缓存,静态缓存)
    php 检测url
    ThinkPHP函数详解:F方法
    图片查看器(图片放大缩小功能)
    Thinkphp路由配置和静态缓存规则【原创】
    mySQL-CRUD操作(数据库的增删改查)练习题
    mySQL CRUD操作(数据库的增删改查)
    初识mySQL(关系型数据库)
  • 原文地址:https://www.cnblogs.com/xyblogs/p/9389151.html
Copyright © 2020-2023  润新知