1,查詢指定父類下所有的子
1 with temp as 2 ( 3 select * from bot_EquityFundamentals where Id=7 --父類Id 4 union all 5 select b.*from bot_EquityFundamentals b 6 inner join 7 temp t on (b.ParentId = t.Id) 8 ) 9 select* from temp order by Id;
2,查詢指定子類所有的父類
1 with temp as 2 ( 3 select * from bot_EquityFundamentals where Id=2143 --子類Id 4 union all 5 select b.* from bot_EquityFundamentals b 6 inner join 7 temp t on (b.Id=t.ParentId) 8 ) 9 select * from temp;