如下表, 給出一個任意 找到所有的父節點, ex 輸入a1 找到 e,a 節點,
id Category FatherID
2 a 0
3 b 0
5 c 2
6 d 2
7 e 2
8 f 6
9 g 5
10 a1 7
11 b1 7
12 c1 3
13 d1 12
15 dw 12
16 de 12
17 fe 16
18 cd 16
19 cg 16
with t as
(
select id, Category,FatherID,0 jibie from Table where Category='a1'
union all
select a.id,a.Category,a.FatherID,t.jibie+1 from Table a inner join t on t.FatherID=a.id
) select * from t where t.jibie>0