语句被终止。完成执行语句前已用完最大递归 9

with cte(u_name,u_referess) as (select u_name,u_referess from userMember where u_referess = 'ceshi' union all select t.u_name,t.u_referess from userMember as t inner join cte as c on t.u_referess = c.u_name ) select COUNT(distinct u_name) from cte option (maxrecursion 9)
我只想递归9次并获取对应的总人数数据,但是报错:语句被终止。完成执行语句前已用完最大递归 9。如何解决控制递归次数不报错并获取对应层数的总人数数据。

sql

2个回答

with cte(
u_name,u_referess,Level
)
as (
select u_name,u_referess,0 from b2ccms_userMember where u_referess = 'ceshi'
union all
select t.u_name,t.u_referess,c.Level+1 as Level from b2ccms_userMember
as t inner join
cte as c on t.u_referess = c.u_name and c.Level<8
)

 我用的是加了一个字段Level,相当于是层数吧
 ![图片说明](https://img-ask.csdn.net/upload/201811/19/1542598259_889726.jpg)

 转载:https://blog.csdn.net/3150379/article/details/54865603

sql server只能递归9层,用java/C#来写你的程序

qq_39464862
qq_39464862 你看下我的方法是不是可行的?
大约一年之前 回复
qq_39464862
qq_39464862 能给个具体的方法吗?(⊙o⊙)…
大约一年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问