zoukankan      html  css  js  c++  java
  • Oracle练习

    1.在scott表中,层次查询老板下面的所有员工

    select level,empno,ename,mgr from emp

    connect by prior empno=mgr

    start with mgr is null

    order by 1;

    执行结果:

    层次查询是单表查询,但是没有办法在这里显示出老板姓名

    2.在scott表中,查询各个老板手下员工的最低工资,最低工资不能低于1000,没有管理者的不包含在内

       显示列名为老板工号,老板姓名,员工最低工资

    --1.显示老板工号和员工最低工资
    select a.mgr "老板工号",min(a.sal) from emp a where a.mgr is not null group by a.mgr having min(a.sal) >=1000;
    --2.根据老板工号查询老板姓名
    select a.empno "员工工号",a.ename "员工姓名",b.empno "老板工号",b.ename "老板姓名" from emp a,emp b where a.mgr=b.empno;
    --3.合在一起
    select a.mgr "老板工号",b.ename "老板姓名",min(a.sal)
    from emp a,emp b
    where a.mgr is not null
    and a.mgr=b.empno
    group by a.mgr,b.ename
    having min(a.sal) >=1000;

    也可采用外连接

    --左连接
    select a.mgr,b.ename,min(a.sal) from emp a
    right join emp b
    on a.mgr=b.empno
    where a.mgr is not null group by a.mgr,b.ename having min(a.sal) >=1000;

    执行结果:

  • 相关阅读:
    两个栈实现一个队列
    DacningLinks实现
    boost::implicit_cast
    hibernate查询之Criteria实现分页方法(GROOVY语法)
    VS2015 android 设计器不能可视化问题解决。
    当Eclipse爱上SVN
    你不知道的getComputedStyle
    推荐的软件
    React之表单
    理解javascript中的Function.prototype.bind
  • 原文地址:https://www.cnblogs.com/shizunatsu/p/11161626.html
Copyright © 2011-2022 走看看