sql树型查询

sql树型查询
WITH a
AS  
(  
SELECT *,
FOrderPath=CAST(RIGHT(1000+FOrder,3) AS NVARCHAR(200)),
FPath=CAST(Id AS NVARCHAR(200)),
FLevel=0
 FROM Base_Class AS a WHERE  NOT EXISTS(SELECT 1 FROM Base_Class WHERE ID=a.PID)  
UNION ALL  
SELECT b.*,
CAST(a.FOrderPath + RIGHT(1000+b.FOrder,3)AS NVARCHAR(200)),
CAST((a.FPath + , + CAST(b.Id AS NVARCHAR(10)))AS NVARCHAR(200)),
FLevel=FLevel+1
 FROM a INNER JOIN Base_Class AS b ON b.PID=a.ID
)
SELECT * FROM a ORDER BY FOrderPath
sql树型查询

sql树型查询

上一篇:ecshop的smarty库还原成smarty原生库方法


下一篇:uni-app 之列表项(uni-list-item不显示边框)