当前位置: 首页 > 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.xdnf.cn/news/1249453.html

相关文章:

  • 科技云报到:Agent应用爆发,谁成为向上托举的力量?
  • 网络编程epoll学习
  • UE编辑器相机窗口运行时相机fov 大小不一致
  • Vue Router 路由的创建和基本使用(超详细)
  • 手动开发一个TCP服务器调试工具(二):无界面 TCP 通信服最小实现
  • Linux网络编程基础-简易TCP服务器框架
  • 大前端游戏应用中 AI 角色行为智能控制
  • 网站、域名、IP在什么场景下需要备案
  • Fabric.js从入门学习到实现labelImg矩形多边形标注工具【上】
  • SmartMediaKit 模块化音视频框架实战指南:场景链路 + 能力矩阵全解析
  • ICCV 2025 | 视频生成迈入“多段一致”新时代!TokensGen用“压缩Token”玩转长视频生成
  • GPU 优化-用 tensor core实现5G Massive MIMO 64x64
  • Linux系统之Docker命令与镜像、容器管理
  • nginx代理出https,request.getRequestURL()得到http问题解决
  • imx6ull-驱动开发篇10——pinctrl 子系统
  • 福彩双色球第2025090期篮球号码分析
  • 生成式 AI 重塑自动驾驶仿真:4D 场景生成技术的突破与实践
  • Spring之【初识AOP】
  • Agent安全机制:权限控制与风险防范
  • 海康威视相机,MVS连接成功,但无图像怎么办?
  • 云计算一阶段Ⅱ——12. SELinux 加固 Linux 安全
  • 统计鱼儿分布情况 Java
  • libpq库使用
  • 二叉树算法
  • Mysql常用语句
  • Bilateral Reference for High-Resolution Dichotomous Image Segmentation
  • 智慧社区(八)——社区人脸识别出入管理系统设计与实现
  • 轻量应用服务器Centos系统上安装jdk8和Jdk17教程(详细)
  • (ZipList入门笔记二)为何ZipList可以实现内存压缩,可以详细介绍一下吗
  • 在AI时代,如何制定有效的职业规划?AI时代职业规划+AI产品经理角色