我有以下问题:我有一个用于维护分层数据的表.我想在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.name FROM OrganizationFeatures ofs JOIN tree ON tree.ID = ofs.ParentID ) select * from tree@H_403_3@但我想按代码排序,结果如下:
1 1/1 1/1/1 1/1/2 1/2/1 1/2/2 2 4/1@H_403_3@等任何想法?