我在postgres中有以下recrusive查询,它给出了一个特定的GeoNames id(在本例中为6429727)获取其名称以及包含它的每个地方的名称和id一直到层次结构:
WITH RECURSIVE geonametree AS
(SELECT geoname.geonameid AS id
, geoname.name AS name
, hierarchy.parentid AS parent
, hierarchy.childid AS child
FROM hierarchy
JOIN geoname ON geoname.geonameid = hierarchy.childid
WHERE geoname.geonameid = 6429727
UNION ALL
SELECT geoname.geonameid AS id
, geoname.name AS name
, hi.parentid AS parent
, hi.childid AS child
FROM hierarchy AS hi
JOIN geoname ON geoname.geonameid = hi.parentid
INNER JOIN geonametree AS gt ON (hi.childid = gt.parent)
)
SELECT id
, name
, parent
, child
FROM geonametree;
我如何在MySQL中实现同样的目标 - 文档不是很清楚,或者我不太了解它。