当前位置:网站首页>mysql 递归
mysql 递归
2022-06-30 17:46:00 【曹振华】
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边栏推荐
- 【社区明星评选】第23期 7月更文计划 | 点滴创作,汇聚成塔!华为FreeBuds 4E等酷爽好礼送不停
- How to seamlessly transition from traditional microservice framework to service grid ASM
- Personally test the size of flutter after packaging APK, quite satisfied
- Swin-Transformer(2021-08)
- 《Go题库·15》go struct 能不能比较?
- 一文详解|Go 分布式链路追踪实现原理
- 不同制造工艺对PCB上的焊盘的影响和要求
- Classic problem of leetcode dynamic programming (I)
- What if the apple watch fails to power on? Apple watch can not boot solution!
- php利用队列解决迷宫问题
猜你喜欢

OneFlow源码解析:算子签名的自动推断

拓維信息使用 Rainbond 的雲原生落地實踐

Leader: who can use redis expired monitoring to close orders and get out of here!

【TiDB】TiCDC canal_json的实际应用

Regular expressions (regular matching)

PC端微信多开

Sword finger offer 17 Print from 1 to maximum n digits

ForkJoinPool

dtd建模

Classic problem of leetcode dynamic programming (I)
随机推荐
《被讨厌的勇气:“自我启发之父”阿德勒的哲学课》
NFT technology for gamefi chain game system development
《Go题库·15》go struct 能不能比较?
Regular expressions (regular matching)
Geoffrey Hinton:我的五十年深度学习生涯与研究心法
Compare the audio librosa library with the Mel spectrogram in the torchaudio library
The cloud native landing practice of using rainbow for Tuowei information
[Collection - industry solutions] how to build a high-performance data acceleration and data editing platform
Tensorflow2 深度学习十必知
电子元器件行业在线采购系统精准匹配采购需求,撬动电子产业数字化发展
3.10 haas506 2.0开发教程-example-TFT
AI chief architect 10-aica-lanxiang, propeller frame design and core technology
When selecting smart speakers, do you prefer "smart" or "sound quality"? This article gives you the answer
20220607跌破建议零售价,GPU市场正全面走向供过于求...
PyTorch学习(三)
How to do a good job in software system demand research? Seven weapons make it easy for you to do it
sqlserver SQL Server Management Studio和Transact-SQL创建账户、创建访问指定数据库的只读用户
Do you really understand the persistence mechanism of redis?
torch stack() meshgrid()
Compilation problems and solutions of teamtalk winclient