当前位置: 首页 > news >正文

mysql 8递归查询

带有排序和层级

 with recursive cte as(select *, cast(order_num as char(1000)) as sort_path, 1 as level from com_office_project_wbs where id = '1942822902508290048'union allselect c.*, concat(cte.sort_path, '-', c.order_num), cte.level + 1  from com_office_project_wbs c, cte where c.parent_id = cte.id)select t.sort_path,t.level, t.* from cte t 
ORDER BY sort_path

在这里插入图片描述

向上查

with recursive cte as
(
select * from com_office_project_wbs where id = '1942824126712381440'
union all
select c.* from com_office_project_wbs c, cte where c.id = cte.parent_id
)
select * from cte t 

在这里插入图片描述

向下查询

	 with recursive cte as
(
select * from com_office_project_wbs where id = '1942822902508290048'
union all
select c.* from com_office_project_wbs c, cte where c.parent_id = cte.id
)
select * from cte t 

在这里插入图片描述

查询孩子节点数量

with recursive cte as(select * from com_office_project_wbs where id = '1942822902508290048'union allselect c.* from com_office_project_wbs c, cte where c.parent_id = cte.id)select IFNULL(count(1),0) cn from cte where id != '1942822902508290048'
http://www.lryc.cn/news/612296.html

相关文章:

  • Java基础学习(三):输入输出、控制流程、大数值、数组
  • 客流特征识别准确率提升 29%:陌讯多模态融合算法在零售场景的实战解析
  • 数据结构与算法的认识
  • Android 之 ViewBinding 实现更安全、高效的视图绑定
  • 【渲染流水线】[应用阶段]-[裁剪]以UnityURP为例
  • CGAL Kernel 和 Traits 类深度解析:从官方教程到实践应用
  • prefetch 下载 GEO 数据注意事项
  • Milvus 向量数据库
  • 使用 Helm 在 Kubernetes 中安装 Milvus
  • 安装向量数据库Milvus
  • C++实现线程池(3)缓存线程池
  • Chrontel昆泰-【CH7036A-BF】CH7036 LVDS to HDMI/VGA/LVDS Converter
  • ​ubuntu22.04系统入门 (四)linux入门命令 权限管理、ACL权限、管道与重定向
  • Qt菜单栏与工具栏实战
  • 学习 Android(十四)NDK基础
  • VGG16训练和测试Fashion和CIFAR10
  • 利用C++11和泛型编程改进原型模式
  • 学习 Android(十五)NDK进阶及性能优化
  • 功能安全和网络安全的综合保障流程
  • 分布式事务Seata、LCN的原理深度剖析
  • vue中reactive()和ref()的用法
  • selenium操作指南
  • 状态模式及优化
  • 【机器学习篇】02day.python机器学习篇Scikit-learn基础操作
  • 如何解决pip安装报错ModuleNotFoundError: No module named ‘gensim’问题
  • Session 和 JWT(JSON Web Token)
  • python:非常流行和重要的Python机器学习库scikit-learn 介绍
  • 毕业设计选题推荐之基于Spark的在线教育投融数据可视化分析系统 |爬虫|大数据|大屏|预测|深度学习|数据分析|数据挖掘
  • Packets Frames 数据包和帧
  • 大数据存储域——Hive数据仓库工具