mysql根据部门ID查询所有子部门

select org_code from (
	select t1.org_code,
	if(find_in_set(org_parentcode, @pids) > 0, @pids := concat(@pids, ',', org_code), 0) as ischild
	from (
			 select org_code,org_parentcode from sp_org t order by org_parentcode, org_code
			) t1,
			(select @pids := '0001') t2
	) t3 where ischild != 0

其中:@pids := '0001’便是所要查询的部门ID

你可能感兴趣的:(mysql)