mysql获取所有父级节点
SELECT
t2.*
FROM
(
SELECT
@r AS _id,
( SELECT @r := department_parent_id FROM department WHERE id = _id ) AS department_parent_id,
@s := @s + 1 AS sort
FROM
( SELECT @r := 35, @s := 0 ) temp,
department
WHERE
@r > 0
) t1
JOIN department t2 ON t1._id = t2.id
ps: department为表名,通过id和department_parent_id字段进行判断上下级关系,上面@r:=35此处是末尾根节点的id,替换此处即可