mysql在8.0.1版本加入了cte递归查询
表结构: || id || pid || name ||
查询id为1的节点以及他所有的子孙节点
with recursive cte as ( select * from tree where id = 1 union all select t.* from tree as t inner join cte on t.pid = cte.id ) select * from cte;