标签:
创建存储过程
DROP FUNCTION `getSubAgent`;
CREATE FUNCTION `getSubAgent` (agentId INT)
RETURNS VARCHAR(4000)
BEGIN
DECLARE sTemp VARCHAR(4000);
DECLARE sTempChd VARCHAR(4000);
SET sTemp = 0;
SET sTempChd = cast(agentId as char);
WHILE sTempChd is not NULL DO
SET sTemp = CONCAT(sTemp,‘,‘,sTempChd);
SELECT group_concat(id) INTO sTempChd FROM wx_agent where FIND_IN_SET(pid,sTempChd)>0;
END WHILE;
return sTemp;
END;
使用SELECT getSubAgent(11);
使用mysql存储过程递归tree(如一个上级下面的所有下级的所有下级。。。。)
标签:
原文地址:http://www.cnblogs.com/xiaonange/p/4596918.html