SELECT
*
FROM
(SELECT
`t1`.*, IF(FIND_IN_SET(`dept_parent_id`, @pids) > 0, @pids := CONCAT(@pids, ',', `id`), 0) AS 'ischild'
FROM
(SELECT * FROM `sm_department` t ORDER BY `dept_parent_id`, `id`) t1,
(SELECT @pids := 2) t2) t3
WHERE
`ischild` != 0 OR `id` = 2;
如不需要id = 2 可去除;