zoukankan      html  css  js  c++  java
  • SQL 实现地区的实现树形结构递归查询(无限级分类),level为节点层级,由小至大依次

    //SQL 实现地区的实现树形结构递归查询(无限级分类),level为节点层级,由小至大依次  2018-09-25
                        StringBuilder areaSQL = new StringBuilder();
                        areaSQL.AppendLine(" with cte_child(id,areaName,pid,level) as ( select id,areaName,pid,0 as level from erp_area ");
                        areaSQL.AppendLine(" where pid = 0 "); //优先列出第一节点 id = 1 指定中国
                        areaSQL.AppendLine(" union all  ");   //递归条件 
                        areaSQL.AppendLine(" select a.id,a.areaName,a.pid,b.level+1  ");
                        areaSQL.AppendLine(" from erp_area a  inner join   cte_child b  on ( a.pid=b.id) ");
                        areaSQL.AppendLine(" ) select  * from cte_child ");
                        DataTable dtArea = sqlhelp.GetDataSet(areaSQL.ToString()).Tables[0];
  • 相关阅读:
    HDU 1813 Escape from Tetris
    BZOJ 2276 Temperature
    BZOJ 4499 线性函数
    BZOJ 3131 淘金
    HDU 5738 Eureka
    POJ 2409 Let it Bead
    POJ 1286 Necklace of Beads
    POJ 1696 Space Ant
    Fox And Jumping
    Recover the String
  • 原文地址:https://www.cnblogs.com/Fooo/p/11295643.html
Copyright © 2011-2022 走看看