-- 查询id为3 及其 子节点WITH RECURSIVE tempAS(SELECT c.*from city c where c.id =3UNIONALLSELECT c.*from city c,tempwhere c.parent_id =temp.id
)SELECT*FROMtemp;
-- 查询id为11 及其 父节点WITH RECURSIVE tempAS(SELECT c.*from city c where c.id =11UNIONALLSELECT c.*from city c,tempwhere c.id =temp.parent_id
)SELECT*FROMtemp;