首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 冲浪宝典 > 网络资源 > connect表连接(含start)
【标  题】:connect表连接(含start)
【关键字】:connect,start
【来  源】:http://www.cublog.cn/u/19112/showart.php?id=170051

connect表连接(含start)

-- 显示从e.mgr is null开始的管理关系,及所在层
select e.ename,e.empno,e.mgr,level "所在层"  --level 所在层
from emp e
start with e.mgr is null -- 从mgr为空开始
connect by e.mgr= prior e.empno  --当前的人员的上级工号是上前一行的人的工号

--各个层的总人数
select level,count(level) "本层人数"
from emp e
start with e.mgr is null
connect by e.mgr= prior e.empno
group by level

--渐进显示管理层次
SELECT LEVEL, LPAD('  ',3*(LEVEL - 1)) || e.ename "EMPLOYEE",e.empno,e.mgr
FROM EMP e
START WITH e.mgr IS NULL
CONNECT BY PRIOR e.empno =e.mgr ;

--控制显示层
select e.ename,e.empno,e.mgr,level "所在层"  ,e.deptno
from emp e
where level >2
start with e.mgr is null
connect by e.mgr= prior e.empno

--多个连接条件
select e.ename,e.empno,e.mgr,level "所在层"  ,e.deptno
from emp e
start with e.mgr is null
connect by e.mgr= prior e.empno and e.deptno=prior e.deptno

--子查询,复查询交叉
select  t2.empno,t2.ename,
        (select count(*)
         from emp t1
         start with t1.empno=t2.empno              --子父查询交叉条件控制
         connect by t1.mgr=prior t1.empno
         ) "统领数"
from emp t2

select e.ename,e.empno,e.mgr "mgr.no",prior e.ename "mgr.name" ---该员工的上级 编号,姓名
from emp e
start with e.mgr is null -- 从mgr为空开始
connect by e.mgr= prior e.empno  --当前的人员的上级工号是上前一行的人的工号

case decode:【上一篇】
OracleCluster_RAID的种类:【下一篇】
【相关文章】
  • SYS_CONNECT_BY_PATH 函数
  • 从修改“Space War Starter Kit”例子学习XNA
  • An error has occurred while establishing a connection to the server.
  • Jumpstart服务器制作实例
  • delphi中使用adoconnection 的openschema的例子源代码
  • 安装biztalk2006后导致QuickStartV20不正常
  • 使用CFtpconnection类实现文件的断点续传的问题
  • Lua入门系列----pil学习笔记之Getting Start
  • Distributed Application --- Start with Database Connection Pool
  • 发行版发布:StartCom Enterprise Linux 3.0.6
  • 【随机文章】
  • 4千万美圆的疑问
  • Swing 中设置模态窗体和启动位置
  • 并行开发版本管理之路(二) --- 典型的版本管理难题
  • 我不得不喜欢的台词
  • 卫星转动效果<1>
  • 论坛推广12招
  • 主流嵌入式Linux动态扩展技术比较分析
  • ASP.NET子页面改变父页面控件的值(子页面刷新父页面)
  • 正则表达式简介(微软)--8.特殊字符
  • cih病毒源代码
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.