MYSQL查询所有父节点

2018-04-04  本文已影响0人  snailever

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;

上一篇 下一篇

猜你喜欢

热点阅读