当前位置: 首页 > 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.dtcms.com/a/317271.html

相关文章:

  • AMD二季度净利润同比下降31%
  • 企业级建模平台Sparx EA的云服务实现全域架构协同
  • imx6ull-驱动开发篇11——gpio子系统
  • django permission_classes = [AllowAny] 如何限制到具体接口
  • 得物向量数据库落地实践
  • 智慧二次供水管理系统解决方案:城市供水“最后一公里”
  • 【面试场景题】电商秒杀系统的库存管理设计实战
  • Docker swarm 常用的命令集合
  • 线轨矫平机:让“钢轨”变直的幕后物理课
  • 移动端网页调试实战,跨设备兼容与触控交互问题排查全流程
  • SassSCSS:让CSS拥有超能力的预处理器
  • `<dependencyManagement>`内部的`<dependencies>`和外部的`<dependencies>`的区别:
  • Spring Boot全局异常处理与日志监控实战指南
  • 浙江大学PTA程序设计C语言基础编程练习题6-10
  • Python爬虫实战:研究Photon工具,构建企业信息收集系统
  • 【Java】HashMap的key可以为null吗?如何存储的?
  • 线性代数中矩阵的基本运算运算
  • 【图像处理基石】浅谈3D城市生成中的数据融合技术
  • 分布式微服务--GateWay(1)
  • 【注意】HCIE-Datacom华为数通考试,第四季度将变题!
  • 基于Hadoop的木鸟民宿数据分析与可视化、民宿价格预测模型系统的设计与实现
  • OpenKruise
  • Linux《进程间通信(上)》
  • Git 乱码文件处理全流程指南
  • 记一次ORACLE ORA-00600 [19004] 错误的分析与解决方法
  • HarmonyOS 5 入门系列-鸿蒙HarmonyOS示例项目讲解
  • 铁路通信信号基础知识点(2)轨旁与车载ATP关系
  • 《动手学深度学习》读书笔记—9.5机器翻译与数据集
  • 虚拟机磁盘扩容
  • centos KVM