sql递归获取所有子节点

2025-01-21 05:00:33
推荐回答(1个)
回答1:

假如表数据如下:
t_id p_id node
1 a
2 1 b
3 1 c
4 2 d
5 2 e
树的形状为
a
| \
b c
| \
d e

递归代码为:select t_id, p_id, node from tree
connect by prior t_id = p_id
start with t_id = 1