首页 > 数据库技术 > 详细

mysql递归查询cte

时间:2021-06-06 21:26:21      阅读:21      评论:0      收藏:0      [点我收藏+]

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;

 

mysql递归查询cte

原文:https://www.cnblogs.com/zhouxuezheng/p/14855907.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!