先上个效果图吧 CTE递归查询里面用了一些小的技巧,查询出结果以后在前端用表格展示出来,层级视觉效果还是很明显的 with tree as(select [ID],[Name],[Address],[Remark],SortNo,Cast(RANK() OVER(order by SortNo,Name) as nvarchar(4000)) Code,cast('' as varchar) as prex from SmartHospital where ID=1union allselect