码迷,mamicode.com
首页 > 数据库 > 详细

ORACLE:start with ... connect by prior

时间:2020-05-01 10:30:14      阅读:86      评论:0      收藏:0      [点我收藏+]

标签:acl   ubi   with   rsa   priority   one   column   class   att   

--start with ... connect by prior
--case1
select * from org o
--excute order=>first:start with connect by prior, then where condition
where o.flag = 1

--start with subNodId=‘...‘ connect by prior subNodeId = parentNodeId
start with o.org_code=10000
--start with parentNodId=‘...‘ connect by prior subNodeId = parentNodeId
start with o.org_parent_code=10000

connect by prior o.org_code=o.org_parent_code


--case2
select * from org o

--start with subNodeId=‘...‘ connect by subNodeId = prior parentNodeId
start with o.org_code=10000
--start with parentNodeId=‘...‘ connect by subNodeId = prior parentNodeId
start with o.org_parent_code=10000

connect by o.org_code=prior o.org_parent_code

--start with clause: 
--There is a little trick to traverse the starting conditions. 
--If you want to check the parent node, you can use the column of the child node and vice versa.

--connect by clause:
--Connection conditions:The key word priority, put together with the parentid of the parent node column, is to traverse toward the parent node;
--put priority together with the child node column subid, then traverse to the direction of the leaf node,

--to sum up: It doesn‘t matter which one puts in front of "=" to parentid and subid, the key point is who keep together with prior.



--CONNECT_BY_ROOT
--qry average salary for each team
select name, avg(sal)
fom
    (select CONNECT_BY_ROOT t.user_name as name, t.user_salary as salary
     from employee
     start with t.emp_no = 10000
     connet by prior t.emp_no = t.manager_no
    )
group by name

 

ORACLE:start with ... connect by prior

标签:acl   ubi   with   rsa   priority   one   column   class   att   

原文地址:https://www.cnblogs.com/xinyueliu/p/12812370.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!