BEGIN DECLARE childOrgIds VARCHAR(4000); DECLARE topOrgIds VARCHAR(4000);
SET childOrgIds = ''; SET topOrgIds = '';
SELECTGROUP_CONCAT(kroa.org_id) INTO topOrgIds FROM kk_role_org_authority kroa WHERE kroa.org_authority_bh IN( SELECT kr.org_authority_bh FROM kk_role kr WHERE kr.role_id IN( SELECT kur.role_id FROM kk_user_role kur WHERE kur.user_id = userId) );
WHILE topOrgIds IS NOT NULL DO SET childOrgIds = CONCAT(childOrgIds, ',', topOrgIds); SELECTGROUP_CONCAT(org_id) INTO topOrgIds FROM kk_org WHERE FIND_IN_SET(father_id, topOrgIds) > 0; ENDWHILE; RETURN RIGHT(childOrgIds, CHAR_LENGTH(childOrgIds)-1); END
SELECT kuo.user_id FROM kk_user_org kuo WHERE kuo.org_id IN(getChildOrgIdsByUserId(100))