//向下递归包含本级
WITH RECURSIVE cte AS (
SELECT * FROM live_usr_config WHERE supid="lNy5ZNI3WZ3QXSopb0mdr"
UNION ALL
SELECT d.* FROM live_usr_config d INNER JOIN cte ON d.supid = cte.subid
)
SELECT * FROM cte;
//向下递归包含本级并限制次数为下两层
WITH RECURSIVE cte (subid, level) AS (
SELECT subid, 1
FROM live_usr_config
WHERE supid="lNy5ZNI3WZ3QXSopb0mdr"
UNION ALL
SELECT o.subid, cte.level + 1
FROM live_usr_config o
INNER JOIN cte ON o.supid = cte.subid
WHERE level < 2
)
SELECT * FROM cte ORDER BY subid;
参考网站:https://www.python100.com/html/7U3P24ALVZ73.html