sqlserver根据父id递归出所有子孙级
假如现在有一张菜单表sys_menu,字段有id,pid,name,现在我想递归出id为5a4f0eace0e1ce32c489d839的菜单的所有子孙菜单。
解决方法:
with temp ( id, pid,name) as
(
select id, pid,name
from sys_menu
where pid = '5a4f0eace0e1ce32c489d839'
union all
select a.id, a.pid,a.name
from sys_menu a
inner join temp on a.pid = temp.id
) select * from temp