我有以下问题:我有一个用于维护分层数据的表.我想在SQL 2005中使用CTE.
WITH tree (id, parentid, code, name) AS ( SELECT id, ofs.ParentID, ofs.code, ofs.name FROM OrganizationFeatures ofs WHERE ofs.ParentID IS NULL UNION ALL SELECT ofs.id, ofs.ParentID, ofs.code, ofs.name FROM OrganizationFeatures ofs JOIN tree ON tree.ID = ofs.ParentID ) select * from tree
但我想按代码排序,结果如下:
1 1/1 1/1/1 1/1/2 1/2/1 1/2/2 2 4/1
等任何想法?