-- 假设节点表结构为:node(id, name, parent_id)
-- id为节点的唯一标识,name为节点名称,parent_id为父节点idWITH RECURSIVE cte (id, name) AS ( SELECT id, name FROM node WHERE id = 1 UNION ALL SELECT node.id, node.name FROM node INNER JOIN cte ON cte.id = node.parent_id ) SELECT * FROM cte;
08-04
2724
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)