递归查询

参考:  https://www.cnblogs.com/chen1388/archive/2010/09/25/1834827.html

 

sql:

select t.* from cms_org_relation t start with t.org_id = '199570057205'
connect by prior t.org_id = t.parent_org order siblings by t.create_time; 

 

说明: 

    start with  : 遍历起始条件

 connect by  : 连接条件

           prior  : 表示上一条记录,比如 prior t.org_id = t.parent_org 就是说上一条记录的 【org_id】 是本条记录的 【parent_org】,即本记录的父亲是上一条记录。 

 

查询结果:

 

 

posted @ 2017-12-20 14:30  不像程序员  阅读(153)  评论(0编辑  收藏  举报