我有以下 CTE 查询
;WITH cte AS (
SELECT 0 AS lvl, id, catName, parent,
CAST(id AS VARCHAR(128)) AS Sort
FROM CategoriesMap WHERE id =2
UNION ALL
SELECT p.lvl + 1, c.id, c.catName, c.parent,
CAST(CAST(c.id AS VARCHAR) + '_' + p.Sort AS VARCHAR(128))
FROM CategoriesMap c
INNER JOIN cte p ON p.parent = c.id
)
select * from cte
排序(树)列有这样的输出(两行)......
2
1_2
哪里,2
是电视类别,1_2
表示这是树状图(1: Internet Tv, 2 = Jadoo Tv)
现在我也可以返回带有类别代码的类别名称吗?
就像是
2:Jadoo Tc
1_Internet Tv: 2_Jadoo Tv
谢谢