zoukankan      html  css  js  c++  java
  • Oracle Connect by与递归with

    层次查询

    select * from emp;

    select empno,

    ename,

    job,

    mgr,

    sal,

    deptno,level lv,

    sys_connect_by_path(ename, '->') tree_path,

    connect_by_root(ename) tree_root,

    connect_by_isleaf isleaf,

    decode(connect_by_isleaf,1,ename,null) tree_leaf

    from emp

    start with empno = 7369

    connect by prior mgr = empno

    order by level,empno;

    with t(empno,

    ename,

    job,

    mgr,

    sal,

    deptno,

    lv,

    tree_path,

    tree_root,

    isleaf,tree_leaf) as

    (select empno,

    ename,

    job,

    mgr,

    sal,

    deptno,

    1 lv,

    '->'||ename,

    ename,

    (select decode(count(1), 0, 1) from emp where a.mgr = empno) isleaf,

    (select decode(count(1), 0, a.ename) from emp where a.mgr = empno) leafname

    from emp a

    where empno = '7369'

    union all

    select a.empno,

    a.ename,

    a.job,

    a.mgr,

    a.sal,

    a.deptno,

    b.lv + 1,

    b.tree_path || '->' || a.ename,

    b.tree_root,

    (select decode(count(1), 0, 1) from emp where a.mgr = empno) isleaf,

    (select decode(count(1), 0,a.ename) from emp where a.mgr = empno) leafname

    from emp a, t b

    where a.empno = b.mgr)

    select * from t order by lv,empno;

  • 相关阅读:
    10.cocos2dx C++为Sprite添加触摸事件监听器
    9.多彩的幕布layer
    8.ZOrder
    7.cocos精灵创建和绘制
    6.cocos2d设置定时器
    5.cocos2d锚点
    4.cocos场景和层的调用
    文件导入导出
    两个整数相乘是否超限
    倒置字符串函数reverse
  • 原文地址:https://www.cnblogs.com/mellowsmile/p/4669519.html
Copyright © 2011-2022 走看看