回答:感觉不像递归呀,你这个子任务里面还分了子任务吗,如果没有的话,只需要查询两次即可,第一次查询主任务,第二次根据主任务查询子任务;如果是子任务分了子任务的,就可以考虑采用JSON格式存储,到时候读出来然后转化,转化完了再写回去,只是JSON的处理会相对麻烦一些
可以参考下这个 http://t.csdn.cn/Ri4NX
或者使用 with recursive 下边这样
with recursive temp as (
select * from sys_menu p
union all
select t.* from sys_menu t inner join temp t2 on t2.id = t.parent_id
)
select * from temp