码迷,mamicode.com
首页 > 编程语言 > 详细

用SYS_CONNECT_BY_PATH进行层级查询时的排序问题

时间:2016-12-13 19:24:33      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:nbsp   color   time   from   sys   asc   tle   select   rom   

 

 

用SYS_CONNECT_BY_PATH进行层级查询时, 对同一级别的节点进行排序,可以加order SIBLINGS by 子句实现

WITH N2 AS(
    SELECT n.ID, org."ParentID", n."NodeName", n."Sort" FROM "Organize" org
    LEFT JOIN "Node" n ON n."ID"=org."NodeID"
    WHERE n."DeleteTime" IS NULL AND n."RefreshTime" is NULL
    ORDER BY "ParentID", "Sort" ASC
)
    SELECT "ID",   "ParentID", "NodeName", 
    SYS_CONNECT_BY_PATH("ID",\)   ID_PATH, SYS_CONNECT_BY_PATH("NodeName",\)  NAME_PATH, LEVEL, "Sort"
    FROM N2

    START   WITH "ParentID"=# OR "ParentID" IS NULL
    CONNECT BY PRIOR "ID"="ParentID"
    order SIBLINGS by "Sort" ASC

 

参考文献:https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1154964870586

用SYS_CONNECT_BY_PATH进行层级查询时的排序问题

标签:nbsp   color   time   from   sys   asc   tle   select   rom   

原文地址:http://www.cnblogs.com/legendjslc/p/6170940.html

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