什么方式得出以下结果啊
我的方式很死,大家帮我写个SQL
VERY 3Q
IF OBJECT_ID(N'TEMPDB..#TB') IS NOT NULL DROP TABLE #TBGOCREATE TABLE #TB(FItemID INT,FName NVARCHAR(100),FParentID INT,FLevel INT)GOINSERT INTO #TBSELECT 1,'佳天大厦',0,1UNION ALLSELECT 2,'六楼',1,2UNION ALLSELECT 3,'6205',2,3UNION ALLSELECT 4,'六楼',1,2UNION ALLSELECT 5,'6207',4,3UNION ALLSELECT 6,'童谣大厦',0,1UNION ALLSELECT 7,'八楼',6,2UNION ALLSELECT 8,'8305',7,3SELECT T1.FName AS FBuildNo,T2.FName AS FLayer,T3.FName AS FRoom FROM #TB T1 INNER JOIN #TB T2 ON T1.FItemID = T2.FParentIDINNER JOIN #TB T3 ON T2.FItemID = T3.FParentIDFBuildNo FLayer FRoom-------------------- -------------------- --------------------佳天大厦 六楼 6205佳天大厦 六楼 6207童谣大厦 八楼 8305(3 行受影响)