with Department_Sub(DeptNO,DeptName,ParentDeptNO) as
(select DeptNO,DeptName,ParentDeptNO from JCSJ_Department where ParentDeptNO=@DeptNO
union all
select A.DeptNO,A.DeptName,A.ParentDeptNO from Department_Sub ,JCSJ_Department A
where Department_Sub.DeptNO=A.ParentDeptNO
)
这段代码中刚开始的时候在union 后面就用了Department_Sub 表达式,但是第一次的时候它就是个表达式怎么会有值呢,还是说第一次执行的时候它里面的值是select DeptNO,DeptName,ParentDeptNO from JCSJ_Department where ParentDeptNO=@DeptNO这个里面搜索出来的值
刚才说的有点问题,应该说select DeptNO,DeptName,ParentDeptNO from JCSJ_Department where ParentDeptNO=@DeptNO这句话参与之后的递归吗
with as union 递归调用怎么判断调用次数,下面代码中是只能递归一次还是有隐含的结束条件
答案:2 悬赏:50
解决时间 2021-04-18 17:24
- 提问者网友:时间却是纷扰
- 2021-04-17 16:32
最佳答案
- 二级知识专家网友:佛说妍妍很渣
- 2021-04-17 16:37
没看明白你说的问题,有没有值 你可以把语句单独拿出来执行。用union all 就是把所有数据合在一起。
union 合并且消除重复
union all 合并且不消除重复
union 合并且消除重复
union all 合并且不消除重复
全部回答
- 1楼网友:桑稚给你看
- 2021-04-17 17:57
第一步:select DeptNO,DeptName,ParentDeptNO from JCSJ_Department where ParentDeptNO=@DeptNO;查出对应的数据放入临时表中
第二步:select A.DeptNO,A.DeptName,A.ParentDeptNO from Department_Sub ,JCSJ_Department A where Department_Sub.DeptNO=A.ParentDeptNO;将第一步的数据用上做连接查询,查出来的数据又放入临时表中;
第三步:继续第二步,直到递归完整张表
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯