利用find_in_set函数和@变量
SELECT
id
FROM
(
SELECT
t1.id,
t1.parent_id,
IF (
find_in_set(parent_id, @pids) > 0,
@pids := concat(@pids, ',', id),
0
) AS childList
FROM
(
SELECT
t.节点id as id,
t.节点父id AS parent_id
FROM
表名 t
ORDER BY
t.parentCode,
t.code
) t1,
(SELECT @pids := '查询节点标识') t2
) t3
WHERE
ischild != 0;