mysql sql 根据父级id查询书所有的子孙级数据
WITH RECURSIVE result (
id,
GoodsTypeName,
parentid
) AS (
SELECT
id,
GoodsTypeName,
parentid
FROM
goodstype
WHERE
id IN(59,60,81,131,135)
UNION ALL
SELECT
i.id,
i.GoodsTypeName,
i.parentid
FROM
goodstype i
JOIN result ON i.parentid = result.id
) SELECT
*
FROM
result
WITH RECURSIVE result (
id,
routename,
routeurl,
typeid,
parentid
) AS (
SELECT
id,
routename,
routeurl,
typeid,
parentid
FROM
table
WHERE
id = 1
UNION ALL
SELECT
i.id,
i.routename,
i.routeurl,
i.typeid,
i.parentid
FROM
table i
JOIN result ON i.parentid = result.id
) SELECT
*
FROM
result