Sql server中递归的用法
来源:互联网 发布:python 私有成员获取值 编辑:程序博客网 时间:2024/05/17 22:18
现有如下表
1.由子类查询父类
with sonTofather as
(
select cid,NAME,Parent_Cid from [Table] where Cid=50023021
union all
select a.Cid,a.Name,a.Parent_Cid from [Table] a join sonTofather b on a.Cid=b.Parent_Cid where b.Parent_Cid is not null
)
select * from sonTofather
结果
2.由父类查子类
WITH lmenu(cid,name,Parent_Cid,level) as
(
SELECT cid,NAME,Parent_Cid,0 level FROM [Table] WHERE Cid=50010099
UNION ALL
SELECT A.Cid,A.NAME,A.Parent_Cid,B.level+1 FROM [Table] A,lmenu B
where A.Parent_Cid = B.Cid
)
SELECT * from lmenu
结果:
0 0
- Sql server中递归的用法
- sql server中递归的实现
- SQL Server 2000 中递归
- Sql Server中Update用法的心得
- Sql Server中Update用法的心得
- SQL Server中Case的不同用法
- Sql Server 2005中distinct的用法?
- SQL Server中CASE的用法
- SQL Server中case的用法
- SQL Server中函数GROUPING的用法
- SQL Server中Merge的用法
- SQL SERVER 中str函数的用法
- SQL Server 中 RAISERROR 的用法
- SQL SERVER 中openrowset的用法
- SQL Server 中 RAISERROR 的用法
- SQL Server 中 RAISERROR 的用法
- SQL Server 中 RAISERROR 的用法
- SQL Server 中 RAISERROR 的用法
- 25. Reverse Nodes in k-Group
- linux 常用命令
- 学习js的笔记--检测类型
- WARNING: erroneous pipeline: no element "ffdec_h264"解决方案
- oracle里面的long,long raw,raw,clob,blob区别 .
- Sql server中递归的用法
- Linux ALSA声卡驱动之五:移动设备中的ALSA(ASoC)
- jsp的各种路径获取
- hdu 1864 最大报销额 (01背包)
- HDU--2053
- Openstack命令收集
- 我的Java开发学习之旅------>Java语言中方法的参数传递机制
- ArcGIS Server JavaScript API 学习笔记
- cocos2dx-2.X Layout设置大小问题