MYSQL 向上递归查询

MYSQL 向上递归查询

SELECT T2.`COURSE_LIST_ID`,T2.`COURSE_LIST_NAME`
FROM ( 
    SELECT 
        @r AS _id, 
        (SELECT @r := PARENT_ID FROM edu_course_list WHERE COURSE_LIST_ID = _id) AS PARENT_ID, 
        @l := @l + 1 AS lvl 
    FROM 
        (SELECT @r := "000000006587ceee0165885534b7038a", @l := "0") vars, 
         edu_course_list  h 
    WHERE @r <> "0") T1 
LEFT JOIN edu_course_list T2 
ON T1._id = T2.COURSE_LIST_ID 
WHERE T2.`PARENT_ID` IS NULL
ORDER BY T1.lvl DESC
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页