试试 这个递归查询函数 :
CREATE 
FUNCTION getChildLst(ps_classid varchar(300) CHARACTER SET utf8)
  RETURNS varchar(1000) CHARSET utf8
BEGIN 
   DECLARE sTemp VARCHAR(1000); 
   DECLARE sTempChd VARCHAR(1000); 
 
   SET sTemp = ''; 
   SET sTempChd = ps_classid; 
 
   WHILE sTempChd is not null DO 
     SET sTemp = concat(sTemp,',',sTempChd); 
      SELECT GROUP_CONCAT(ClassId)  INTO sTempChd from   table_anme  where   FIND_IN_SET(FatherId,sTempChd)>0; 
   END WHILE; 
   RETURN sTemp; 
 END ;
希望对你有帮助 (如果数据量过大的话,会比较慢)

解决方案 »

  1.   

    http://blog.csdn.net/acmain_chm/article/details/4142971
    MySQL中进行树状所有子节点的查询
    在Oracle 中我们知道有一个 Hierarchical Queries 通过CONNECT BY 我们可以方便的查了所有当前节点下的所有子节点。但很遗憾,在MySQL的目前版本中还没有对应的功能。 在MySQL中如果是有限的层次,比如我们事先如果可以确定这个树的最大深度是4, 那么所有节点为根的树的深度均不会超过4,则我们可以直接通过left join 来实现。 但很多时候我们...
      

  2.   

    你这个简单就三层,直接三次连接就好了select  a.classStr ,b.classStr,c.classStr  from  t a  
    left join t b on a.ClassId=b.fatherId
    left join t c on b.ClassId=c.fatherId
    where a.classStr isnot null and b.classstr is not null
    然后根据栏位名去处为null的就是了大概就这样,是不是空你根据具体值筛选下,我不知道你的数据什么情况