我有一张这样的表
ID GroupName ParentID IsFinal
1 Operator Interface 0 0
2 Ways to Access 1 0
3 Network Communication 1 0
4 Ways of Alarm Reporting 1 0
5 Desktop 2 1
6 POT 2 1
7 LAN 3 1
8 SMS 4 1
我需要一个结果
ID GroupName Parent1 Parent2 ...N.. IsFinal
1 Operator Interface NA NA 0
2 Ways to Access Operator Interface NA 0
3 Network Communication Operator Interface NA 0
4 Ways of Alarm Reporting Operator Interface NA 0
5 Desktop Ways to Access Operator Interface 1
6 POT Ways to Access Operator Interface 1
7 LAN Network CommunicationOperator Interface 1
8 SMS ....
我正在进行自我加入,它没有给出理想的结果。
select * from dbo.Table m left outer join dbo.Table n
on m.ParentID = n.ID
还有其他办法吗?