根据第二个问题的sql做一下调整即可
with recursive type_cte as ( select cat_id,name,parent_cid from t_category where cat_id = 40 union all select t.cat_id,concat(type_cte2.name,'>',t.name),t.parent_cid from t_category t inner join type_cte type_cte2 on t.cat_id = type_cte2.parent_cid ) select cat_id, name, parent_cid from type_cte;
+--------+----------------+------------+
| cat_id | name | parent_cid |
+--------+----------------+------------+
| 40 | 防晒 | 13 |
| 13 | 防晒>护肤 | 12 |
| 12 | 防晒>护肤>美妆 | 0 |
+--------+----------------+------------+
总结
到此这篇关于Mysql8.0递归查询的文章就介绍到这了,更多相关Mysql8.0递归查询内容请搜索
更多Mysql内容来自木庄网络博客
标签:Mysql
相关阅读 >>
更多相关阅读请进入《mysql》频道 >>

数据库系统概念 第6版
本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。