玩这个,看看你得到了什么:
SELECT
t1.Title as Group1,
t2.Title as Group2,
t3.Title as Group3,
t4.Title as Group4,
t5.Title as Group5,
a1.Title as SubGroup1,
a2.Title as SubGroup2,
a3.Title as SubGroup3,
a4.Title as SubGroup4,
a5.Title as SubGroup5,
t1.parentGroupID,
t2.parentGroupID,
t3.parentGroupID,
t4.parentGroupID,
t5.parentGroupID,
a1.Balance,
a2.Balance,
a3.Balance,
a4.Balance,
a5.Balance
FROM GROUPS t1
LEFT JOIN GROUPS t2 ON t2.parentGroupID = t1.ID
LEFT JOIN GROUPS t3 ON t3.parentGroupID = t2.ID
LEFT JOIN GROUPS t4 ON t4.parentGroupID = t3.ID
LEFT JOIN GROUPS t5 ON t5.parentGroupID = t4.ID
LEFT OUTER JOIN ACCOUNTS a1 ON a1.GroupID = t1.ID
LEFT OUTER JOIN ACCOUNTS a2 ON a2.GroupID = t2.ID
LEFT OUTER JOIN ACCOUNTS a3 ON a3.GroupID = t3.ID
LEFT OUTER JOIN ACCOUNTS a4 ON a4.GroupID = t4.ID
LEFT OUTER JOIN ACCOUNTS a5 on a5.GroupID = t5.ID
WHERE t1.parentGroupID = 0