Sql Server中通过父记录查找出所有关联的子记录(可查4级Sql代码)

select menu_id,menu_name,Father_Id from Sys_Menu where menu_id='18' or Father_Id=18 or -- 一级、二级
Father_Id in (select menu_id from Sys_Menu a where  menu_id='18' or Father_Id=18) or   -- 三级
father_id in (select menu_id from sys_menu where Father_Id in (select menu_id from Sys_Menu a where  menu_id='18' or Father_Id=18)) -- 四级


select menu_id,menu_name,Father_Id from Sys_Menu where menu_id='18' or Father_Id=18 or -- 一级、二级

Father_Id in (select menu_id from Sys_Menu a where  menu_id='18' or Father_Id=18) or   -- 三级
father_id in (select menu_id from sys_menu where Father_Id in (select menu_id from Sys_Menu a where  menu_id='18' or Father_Id=18)) -- 四级
阅读更多
换一批

没有更多推荐了,返回首页