请教各位前辈,如何 用SQL语句实现由图一变成图二的排列顺序,谢谢。
------解决思路----------------------
递归生成树之后,再按顺序取其记录
------解决思路----------------------
WITH CTE AS(TAB换成你的表,SQL 2005+有效
SELECT *,CAST(menuID AS VARCHAR(8000))'PATH'FROM TAB WHERE ParentID=0
UNION ALL
SELECT A.*,B.[PATH]+'-'+CAST(A.menuID AS VARCHAR(10)) FROM TAB A INNER JOIN CTE B ON A.ParentID=B.menuID
)
SELECT * FROM CTE ORDER BY PATH