CTE实现树形结构查询

WITH cte AS(
   SELECT cate.id,cate.title,cate.parent_id FROM dbo.dt_article_category AS cate WHERE cate.id = 1
   UNION ALL
   SELECT cate.id,cate.title,cate.parent_id  FROM dbo.dt_article_category AS cate JOIN  cte  ON  cate.parent_id = cte.id
)
SELECT * FROM cte

效果:

 

posted on 2018-03-08 15:58  潇潇@暮雨  阅读(361)  评论(0编辑  收藏  举报

导航