SELECT T2.son_id, T2.name
FROM (
SELECT
@r AS _id,
(SELECT @r := parent_id FROM demo WHERE son_id = _id) AS parent_id,
@l := @l + 1 AS lvl
FROM
(SELECT @r := 4, @l := 0) vars,
demo h
WHERE @r <> 0) T1
JOIN demo T2
ON T1._id = T2.son_id
ORDER BY T1.lvl DESC
mysql根据子类递归父类
最新推荐文章于 2024-08-19 16:10:28 发布