Sql 递归查询

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;
查询所有父类

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章