当前位置:网站首页>MySQL recursion
MySQL recursion
2022-06-30 19:11:00 【Caozhenhua】
DROP FUNCTION IF EXISTS GetChildren;
CREATE FUNCTION GetChildren(InputDeptId char(36))
RETURNS VARCHAR(4000)
BEGIN
declare deptIds VARCHAR(4000) default '';
select CONCAT(@pids,',',IFNULL(GROUP_CONCAT(DeptId),'$')) into deptIds from (
select t1.DeptId,
if(find_in_set(UpperId, @pids) > 0,
@pids := concat(@pids, ',', DeptId), 0) as ischild
from (
select DeptId,UpperId from MDM_Dept t
where t.STATUS=1
order by UpperId, DeptId
) t1,
(select @pids := InputDeptId) t2
) t3 where ischild != 0 ;
return deptIds;
END;
select * from MDM_Dept
where FIND_IN_SET(DeptId, GetChildren('b9d22dc7-5651-4e87-a59b-7f11ef178e45'))
select * from
(
select GetFullPath(DeptId) fullPath,DeptId,`Name`,UpperId
from MDM_Dept
where FIND_IN_SET(DeptId, GetChildren('b9d22dc7-5651-4e87-a59b-7f11ef178e45'))
) t order by t.fullPath边栏推荐
- Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system
- Cloud Native Landing Practice Using rainbond for extension dimension information
- 系统集成项目管理工程师认证高频考点:编制项目范围管理计划
- Unlimited cloud "vision" innovation | the 2022 Alibaba cloud live summit was officially launched
- 开发那些事儿:Linux系统中如何安装离线版本MySQL?
- 【TiDB】TiCDC canal_ Practical application of JSON
- Leader: who can use redis expired monitoring to close orders and get out of here!
- The easynvr platform equipment channels are all online. What is the reason for the "network request failure" in the operation?
- Where do the guests come from
- 《被讨厌的勇气:“自我启发之父”阿德勒的哲学课》
猜你喜欢

Reading notes of "high EQ means being able to talk"

Unlimited cloud "vision" innovation | the 2022 Alibaba cloud live summit was officially launched

20220528【聊聊假芯片】贪便宜往往吃大亏,盘点下那些假的内存卡和固态硬盘

Swin-transformer --relative positional Bias

【TiDB】TiCDC canal_json的实际应用
![[Collection - industry solutions] how to build a high-performance data acceleration and data editing platform](/img/56/9f3370eac60df182971607aa642dc2.jpg)
[Collection - industry solutions] how to build a high-performance data acceleration and data editing platform

Detailed single case mode

系统集成项目管理工程师认证高频考点:编制项目范围管理计划

Dlib library for face key point detection (openCV Implementation)

正则表达式(正则匹配)
随机推荐
Tensorflow2 ten must know for deep learning
【TiDB】TiCDC canal_json的实际应用
PC端微信多开
联想YOGA 27 2022,超强配置全面升级
Swin-transformer --relative positional Bias
Redis beginner to master 01
《所谓情商高,就是会说话》读书笔记
MRO industrial products procurement management system: enable MRO enterprise procurement nodes to build a new digital procurement system
屏幕显示技术进化史
Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system
Courage to be hated: Adler's philosophy class: the father of self inspiration
openGauss数据库源码解析系列文章—— 密态等值查询技术详解(上)
Swin-Transformer(2021-08)
亲测flutter打包apk后大小,比较满意
PHP uses queues to solve maze problems
20220607跌破建议零售价,GPU市场正全面走向供过于求...
链表中环的入口结点-链表专题
Dependencies tool to view exe and DLL dependencies
Rust 如何实现依赖注入?
SaaS project management system solution for the financial service industry helps enterprises tap a broader growth service space