with temp_obs as
(
select obs_id,obs_name,parent_obs_id,1 as [level] from obs where enable_flag=1
and proj_id=’AAAAA’ AND parent_obs_id IS null
union all
select A.obs_id,A.obs_name,A.parent_obs_id,B.[level]+1 from obs A,temp_obs B where A.parent_obs_id=B.obs_id
AND enable_flag=1
and proj_id=’AAAAA’
)
select * from temp_obs
MSSqlserver取层级数量
最新推荐文章于 2022-03-28 11:50:25 发布
本文介绍了一种使用SQL实现层次结构查询的方法,通过递归联合的方式,从数据库中获取具有层级关系的数据。具体展示了如何设置递归查询的起始条件及递归规则,适用于需要展示树状结构数据的应用场景。
2281

被折叠的 条评论
为什么被折叠?



