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
效果: