主要通过 WITH RECURSIVE 来实现。
例如一张表的字段:id,code,name,parent_id , 其中 parent_id -> id 形成递归树形结构。
具体查询语句如下:
WITH RECURSIVE grids as (
select * from t_grid where code = #{code}
union all
select * from t_grid where parent_id = grids.id
) select * from grids;