mysql树查询,sql递归函数 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