美文网首页
MYSQL查询所有父节点

MYSQL查询所有父节点

作者: snailever | 来源:发表于2018-04-04 14:08 被阅读0次

SELECT T2.*

FROM (

    SELECT

        @r AS _id,

        (SELECT @r := PAR_MENU_ID FROM TS_SYS_MENU WHERE MENU_ID = _id) AS PAR_MENU_ID,

        @l := @l + 1 AS lvl

    FROM

        (SELECT @r := 32, @l := 0) vars,

          TS_SYS_MENU h

          WHERE @r <> 0) T1

JOIN TS_SYS_MENU T2

ON T1._id = T2.MENU_ID 

ORDER BY T1.lvl DESC;

相关文章

网友评论

      本文标题:MYSQL查询所有父节点

      本文链接:https://www.haomeiwen.com/subject/tepkhftx.html