select cateID from goodscategory where FIND_IN_SET(cateID ,getGoodsChildLst('43242'))
CREATE FUNCTION `getGoodsChildLst`(rootId CHAR(32))
RETURNS varchar(1000)
BEGIN
DECLARE sTemp VARCHAR(1000);
DECLARE sTempChd VARCHAR(1000);
SET sTemp = '$';
SET sTempChd =cast(rootId as CHAR);
WHILE sTempChd is not null DO
SET sTemp = concat(sTemp,',',sTempChd);
SELECT group_concat(cateID) INTO sTempChd FROM goodscategory where FIND_IN_SET(parentCateID,sTempChd)>0;
END WHILE;
RETURN sTemp;
END
本文转自yjflinchong 51CTO博客,原文链接:http://blog.51cto.com/yjflinchong/1165075,如需转载请自行联系原作者