zoukankan      html  css  js  c++  java
  • 查询语句练习


    1、创建表my_emp和emp表具有相同的结构和记录。
               drop table my_emp;
        create table my_emp(
                    EMPNO    NUMBER(4)    not null,                          
                    ENAME    VARCHAR2(10) ,                         
                    JOB      VARCHAR2(9) ,                         
                    MGR      NUMBER(4)  ,                          
                    HIREDATE DATE    ,                             
                    SAL      NUMBER(7,2)  ,                         
                    COMM     NUMBER(7,2) ,                         
                    DEPTNO   NUMBER(2)                          
                     )


    insert into my_emp (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
    values (7369, 'SMITH', 'CLERK', 7902, to_date('17-12-1980', 'dd-mm-yyyy'), 800.00, null, 20);

    insert into my_emp (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
    values (7499, 'ALLEN', 'SALESMAN', 7698, to_date('20-02-1981', 'dd-mm-yyyy'), 1600.00, 300.00, 30);

    insert into my_emp (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
    values (7521, 'WARD', 'SALESMAN', 7698, to_date('22-02-1981', 'dd-mm-yyyy'), 1250.00, 500.00, 30);

    insert into my_emp (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
    values (7566, 'JONES', 'MANAGER', 7839, to_date('02-04-1981', 'dd-mm-yyyy'), 2975.00, null, 20);

    insert into my_emp (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
    values (7654, 'MARTIN', 'SALESMAN', 7698, to_date('28-09-1981', 'dd-mm-yyyy'), 1250.00, 1400.00, 30);

    insert into my_emp (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
    values (7698, 'BLAKE', 'MANAGER', 7839, to_date('01-05-1981', 'dd-mm-yyyy'), 2850.00, null, 30);

    insert into my_emp (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
    values (7782, 'CLARK', 'MANAGER', 7839, to_date('09-06-1981', 'dd-mm-yyyy'), 2450.00, null, 10);

    insert into my_emp (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
    values (7788, 'SCOTT', 'ANALYST', 7566, to_date('19-04-1987', 'dd-mm-yyyy'), 3000.00, null, 20);

    insert into my_emp (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
    values (7839, 'KING', 'PRESIDENT', null, to_date('17-11-1981', 'dd-mm-yyyy'), 5000.00, null, 10);

    insert into my_emp (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
    values (7844, 'TURNER', 'SALESMAN', 7698, to_date('08-09-1981', 'dd-mm-yyyy'), 1500.00, 0.00, 30);

    insert into my_emp (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
    values (7876, 'ADAMS', 'CLERK', 7788, to_date('23-05-1987', 'dd-mm-yyyy'), 1100.00, null, 20);

    insert into my_emp (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
    values (7900, 'JAMES', 'CLERK', 7698, to_date('03-12-1981', 'dd-mm-yyyy'), 950.00, null, 30);

    insert into my_emp (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
    values (7902, 'FORD', 'ANALYST', 7566, to_date('03-12-1981', 'dd-mm-yyyy'), 3000.00, null, 20);

    insert into my_emp (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
    values (7934, 'MILLER', 'CLERK', 7782, to_date('23-01-1982', 'dd-mm-yyyy'), 1300.00, null, 10);
    2、给myemp的empno列添加主建约束。
    alter table my_emp add constraint my_emp_empno_pk primary key(empno);

    3、给myemp添加一条记录。
    insert into my_emp
    values (7935, 'WANG', 'CLERK', 7782, to_date('23-01-1982', 'dd-mm-yyyy'), 1300.00, null, 10);

    4、给myemp添加一条记录只有empno,ename,mgr,sal,deptno有值,其他列为空。

    insert into my_emp(EMPNO, ENAME,  MGR, SAL, DEPTNO) values (
     7936,'XI',7782,1400,10);
    5、显示所有薪金高于公司均薪金的人。
    select *from my_emp where sal>(select avg(sal)from my_emp)  ;



        
    6、给所有10部门的经理(MANAGER)和20部门的职员(CLERK),增加薪金10%。
    update (select * from my_emp where deptno=10 and job='MANAGER'or deptno='20'and job='CLERK')
     set sal=sal*(1+10/100);

    7、使用EMP,DEPT表显示所有销售部'SALES'的员工。
    select * from emp where deptno=(select deptno from dept where dname='SALES');

    8、删除DEPT中没有员工的部门。
     delete dept where deptno=(select deptno from dept where deptno not in(select deptno from emp));

    9、删除雇佣年限低于20年的员工。
    delete emp where hiredate=(select hiredate from emp where (sysdate-hiredate)/365<20 );

    10、显示薪金最高的3位员工
    select * from(select a.*,rownum rn from (select * from emp order by sal desc) a) b where b.rn<=3;

    11、显示10部门薪金前二名的员工
     select* from(select a.*,rownum rn from (select *from emp where deptno=10 order by sal desc) a) b where b.rn<=2;

  • 相关阅读:
    Python之future对象
    Mac上使用SQL Server作为开发用数据库
    EntityFramework Core CLI Tools 几点坑
    EasyExcel根据报表模板来填充报表(多sheet页填充、封装工具方法)
    【linux基础】解决shell错误:syntax error: unexpected end of file
    【DL基础】网络结构参数数量及大小的计算
    【CV基础】Residual Network(ResNet)
    【DL基础】模型训练测试过程消耗内存的计算
    【c++基础】c++中string 的replace用法
    【python基础】python 从list中随机取值的方法
  • 原文地址:https://www.cnblogs.com/w-xibao/p/7816313.html
Copyright © 2011-2022 走看看