当前位置:首页 > 技术心得 > 正文内容

CTE递归限制次数

xjtudll4年前 (2022-03-09)技术心得4620

https://blog.csdn.net/weixin_30247159/article/details/98657005

CTE可以用来取递归,网上资料很多,这里就不再叙述了,今天遇到的需求是要限制只取2级,然后加了个临时的lev

with tree as
(
select [CustomerID],[CustomerName],[PositionParentID],[PositionValus],[Status],[MemberLevelID],Lev=1 from [MallCustomer] where [PositionParentID] = '0017556dece149919af4b91442cf2117'
union all
select a.[CustomerID],a.[CustomerName],a.[PositionParentID],a.[PositionValus],a.[Status],a.[MemberLevelID],Lev+1 Lev from [MallCustomer] a,tree b where a.PositionParentID=b.CustomerID and Lev<=1
)
select  a.[CustomerID],a.[CustomerName],a.[PositionParentID],a.[PositionValus],a.[Status],b.[MemberLevelName] from tree a,MallMemberLevel b where a.MemberLevelID=b.MemberLevelID

这里是层数限制

lev<=1

结果图

703795-20160424213737226-46839029

扫描二维码推送至手机访问。

版权声明:本文由鸟的天空发布,如需转载请注明出处。

本文链接:http://www.xjtudll.cn/Exp/637/

标签: SQL
分享给朋友:

“CTE递归限制次数” 的相关文章

系统能识别光盘,双击打不开

操作系统:Windows 7 现象:自己刻录的一张光盘,放进光驱后,能识别光盘,但是双击后无任何反应。 原因: 这个问题是Win7的一个功能导致的,启用将可能导致无法浏览打开光盘目录,只能加载自动运行程序或自动播放媒体文件,如果没有则无法使用,禁用此功能即可解决问题。 解决方法: 1...

Android 6.0:收不到BluetoothDevice.ACTION_FOUND广播

Android 6.0:收不到BluetoothDevice.ACTION_FOUND广播

参考资料: http://stackoverflow.com/questions/32656510/register-broadcast-receiver-dynamically-does-not-work-bluetoothdevice-action-f https://developer.and...

利用Multisim设计数字滤波器

利用Multisim设计数字滤波器

【工具】->【Circuit Wizards】->【Filter Wizard】  可以设计低通,高通,带通,带阻,滤波器可以选是无源还是有源。不过这玩意儿还是没专业的滤波器设计软件好用。...

ios ble:didDiscoverPeripheral没有回调

参考资料: http://stackoverflow.com/questions/26320578/diddiscoverperipheral-not-been-called-after-advertising-another-ios-device 问题: 启动scan之后,didDiscoverP...

vc中如何获取修改系统时间的消息

参考资料:http://msdn.microsoft.com/en-us/library/windows/desktop/ms725498%28v=vs.85%29.aspx 问题: 我在窗口上显示了系统时间,点击后调出系统的“日期和时间 属性”对话框,修改属性...

C# WinForm中禁止改变窗口大小的方法

C# WinForm中禁止改变窗口大小的方法

在Form类下面有一个FormBorderStyle的字段,我们可以通过设置它的值来让窗体不能被拉大拉小。FormBorderStyle的值设置为FormBorderStyle.FixedSingle或Fixed3D时,窗体大小是不能被改变的。 当然,还有一种情况,我们也应该要考虑到,那就是窗体最...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。