1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢(xún)
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時(shí)間:8:30-17:00
      你可能遇到了下面的問(wèn)題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
      SqlServer中怎么利用公用表表達(dá)式實(shí)現(xiàn)無(wú)限級(jí)樹(shù)形構(gòu)建

      SqlServer中怎么利用公用表表達(dá)式實(shí)現(xiàn)無(wú)限級(jí)樹(shù)形構(gòu)建,針對(duì)這個(gè)問(wèn)題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問(wèn)題的小伙伴找到更簡(jiǎn)單易行的方法。

      創(chuàng)新互聯(lián)專(zhuān)業(yè)提供成都二樞服務(wù)器租用托管服務(wù),為用戶(hù)提供五星數(shù)據(jù)中心、電信、雙線接入解決方案,用戶(hù)可自行在線購(gòu)買(mǎi)成都二樞服務(wù)器租用托管服務(wù),并享受7*24小時(shí)金牌售后服務(wù)。

      SQL Server 2005開(kāi)始,我們可以直接通過(guò)CTE來(lái)支持遞歸查詢(xún),CTE即公用表表達(dá)式

      公用表表達(dá)式(CTE),是一個(gè)在查詢(xún)中定義的臨時(shí)命名結(jié)果集將在from子句中使用它。每個(gè)CTE僅被定義一次(但在其作用域內(nèi)可以被引用任意次),并且在該查詢(xún)生存期間將一直生存。可以使用CTE來(lái)執(zhí)行遞歸操作。

      DECLARE @Level INT=3;WITH cte_parent(CategoryID,CategoryName,ParentCategoryID,Level)AS(  SELECT category_id,category_name,parent_category_id,1 AS Level  FROM TianShenLogistic.dbo.ProductCategory WITH(NOLOCK) WHERE category_id IN ( SELECT category_id  FROM TianShenLogistic.dbo.ProductCategory  WHERE parent_category_id=0 )  UNION ALL  SELECT b.category_id,b.category_name,b.parent_category_id,a.Level+1 AS Level  FROM TianShenLogistic.dbo.ProductCategory b  INNER JOIN cte_parent a  ON a.CategoryID = b.parent_category_id)SELECT  CategoryID AS value, CategoryName as label, ParentCategoryID As parentId, LevelFROM cte_parent WHERE Level <=@Level;public static List GetLogisticsCategoryByParent(int? level)    {      if (level < 1) return null;      var dataResult = CategoryDA.GetLogisticsCategoryByParent(level);      var firstlevel = dataResult.Where(d => d.level == 1).ToList();      BuildCategory(dataResult, firstlevel);      return firstlevel;    }    private static void BuildCategory(List allCategoryList, List categoryList)    {      foreach (var category in categoryList)      {        var subCategoryList = allCategoryList.Where(c => c.parentId == category.value).ToList();        if (subCategoryList.Count > 0)        {          if (category.children == null) category.children = new List();          category.children.AddRange(subCategoryList);          BuildCategory(allCategoryList, category.children);        }      }    }

      關(guān)于SqlServer中怎么利用公用表表達(dá)式實(shí)現(xiàn)無(wú)限級(jí)樹(shù)形構(gòu)建問(wèn)題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒(méi)有解開(kāi),可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識(shí)。


      網(wǎng)頁(yè)標(biāo)題:SqlServer中怎么利用公用表表達(dá)式實(shí)現(xiàn)無(wú)限級(jí)樹(shù)形構(gòu)建
      當(dāng)前路徑:http://www.ef60e0e.cn/article/psddes.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        都江堰市| 建湖县| 嘉鱼县| 岗巴县| 台北市| 佳木斯市| 常山县| 剑河县| 板桥市| 洞口县| 湖北省| 冕宁县| 五家渠市| 五峰| 聂荣县| 泊头市| 黑山县| 芷江| 明星| 潢川县| 仲巴县| 巩留县| 苏尼特右旗| 渭源县| 鹤岗市| 漯河市| 鄄城县| 政和县| 林州市| 贡觉县| 广宗县| 双流县| 景泰县| 井陉县| 龙岩市| 华宁县| 甘谷县| 绵竹市| 博野县| 栖霞市| 文水县|