当前位置:网站首页>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
边栏推荐
- Four tips tell you how to use SMS to promote business sales?
- 「经验」浅谈聚类分析在工作中的应用
- Is it safe to open a mobile stock account? Is it reliable?
- PHP uses queues to solve maze problems
- How does rust implement dependency injection?
- 如何利用AI技术优化独立站客服系统?听听专家怎么说!
- 【社区明星评选】第23期 7月更文计划 | 点滴创作,汇聚成塔!华为FreeBuds 4E等酷爽好礼送不停
- 冰河老师的书
- LeetCode动态规划经典题(一)
- Word——Word在试图打开文件时遇到错误的一种解决办法
猜你喜欢
iCloud照片无法上传或同步怎么办?
Multipass Chinese document - setting graphical interface
When selecting smart speakers, do you prefer "smart" or "sound quality"? This article gives you the answer
系统集成项目管理工程师认证高频考点:编制项目范围管理计划
Detailed single case mode
Multipass中文文档-设置图形界面
opencv数据类型代码表 dtype
The cloud native landing practice of using rainbow for Tuowei information
领导:谁再用 Redis 过期监听实现关闭订单,立马滚蛋!
3.10 haas506 2.0 development tutorial example TFT
随机推荐
《被讨厌的勇气:“自我启发之父”阿德勒的哲学课》
PC端微信多开
浏览器窗口切换激活事件 visibilitychange
The cloud native landing practice of using rainbow for Tuowei information
屏幕显示技术进化史
Countdowncatch and completabilefuture and cyclicbarrier
不同制造工艺对PCB上的焊盘的影响和要求
NFT technology for gamefi chain game system development
depends工具查看exe和dll依赖关系
Merged binary tree of leetcode
torch.roll
【社区明星评选】第23期 7月更文计划 | 点滴创作,汇聚成塔!华为FreeBuds 4E等酷爽好礼送不停
Cobbler轻松上手
OneFlow源码解析:算子签名的自动推断
一套十万级TPS的IM综合消息系统的架构实践与思考
小程序容器技术,促进园区运营效率提升
系统集成项目管理工程师认证高频考点:编制项目范围管理计划
20200525-生物技术-四川师范大学自考生物技术(本科)考试计划.txt
医院在线问诊小程序源码 互联网医院源码 智慧医院源码
亲测flutter打包apk后大小,比较满意