mysql递归查询cte

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;

 

上一篇:Asp.Net WebApi接口返回值IHttpActionResult


下一篇:SQL With As 用法