Mysql 通过父节点ID获取所有子节点数据函数

时间:2017-08-11 00:54:10   收藏:0   阅读:1197

BEGIN
DECLARE sTemp text;
DECLARE sTempChd text;

SET sTemp = ‘$‘;
SET sTempChd =cast(rootId as CHAR);

WHILE sTempChd is not null DO
SET sTemp = concat(sTemp,‘,‘,sTempChd);
SELECT group_concat(deptId) INTO sTempChd FROM ch_class where FIND_IN_SET(deptParId,sTempChd)>0;
END WHILE;
RETURN sTemp;
END

select * from ch_class where FIND_IN_SET(deptId,getParLst((SELECT MIN(id) from ch_class where kdgId = 机构ID))) GROUP BY deptParId;

原文:http://www.cnblogs.com/Bengi/p/7342721.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!