http://www.cnblogs.com/tiancai/articles/2145294.html
http://crackedzone.com/blog/about-unlimited-class-database-analyse.html
http://blog.csdn.net/wangdeng1314/article/details/6430619
如果返回所有数据,基本是在后台处理。应用递归思想。
返回某个分支,可以用like parentids思想,避免了数据库递归查询所有有效节点。
ORDER BY parentid_list
只能返回当前层级下的所有子层级的数据,但不会有层级显示。
CREATE FUNCTION `queryChildrenAreaInfo` (Id INT)
RETURNS VARCHAR (4000)
BEGIN
DECLARE sTemp VARCHAR(400);
DECLARE sTempChd VARCHAR(400);
SET sTemp = '$';
SET sTempChd = cast(Id as char);
WHILE sTempChd is not NULL DO
SET sTemp = CONCAT(sTemp,',',sTempChd);
SELECT group_concat(org_Id) INTO sTempChd FROM sys_organise where FIND_IN_SET(org_parentId,sTempChd)>0;
END WHILE;
return sTemp;
END
调用方式:select queryChildrenAreaInfo(1);
select * from t_areainfo where FIND_IN_SET(id, queryChildrenAreaInfo(20));