//parent_id 父类id member_id 子id , m_member_relation 表
SELECT T2.parent_id
FROM
(SELECT @r AS _member_id,
(SELECT @r := parent_id
FROM m_member_relation
WHERE member_id= _member_id) AS parent_id, @l := @l + 1 AS lvl
FROM
(SELECT @r := $root, @l := 0) vars,
m_member_relation h
WHERE @r <> 0) T1
JOIN m_member_relation T2 ON T1._member_id = T2.member_id
ORDER BY T1.lvl DESC
mysql 根据子类id查询所有父类id
最新推荐文章于 2024-08-19 16:10:28 发布