我有一个像这样的分层数据表:
BookGroupID GroupName ParentGroupID
----------- --------- -------------
0 Primary 0
1 abc 0
2 abd 0
3 abe 0
4 cbc 1
5 ceg 2
6 cjd 3
7 hjd 5
8 bjy 5
9 mfs 4
10 ikl 7
11 hjy 8
12 mnf 5
13 aws 10
14 qws 11
15 aqe 13
Run Code Online (Sandbox Code Playgroud)
我想在层次结构中选择一个特定的 BookGroupID 及其所有直接和间接子级。例如,对于 2 的 BookGroupID,输出应如下所示:
BookGroupID
-----------
2
5
7
8
10
11
12
13
14
15
Run Code Online (Sandbox Code Playgroud)
解释一下,第 5 行在输出中,因为它是第 2 行的直接孩子,第 7、8 和 …