Sql 递归查询
来源:互联网 发布:淘宝网男式手提包 编辑:程序博客网 时间:2024/05/17 01:59
--创建查询函数
create function f_id(
@id int--要查询的id
)returns @re table(id int,level int)
as
begin
declare @l int
set @l=0
insert @re select id,@l
from 表
where 上级id=@id
while @@rowcount>0
begin
set @l=@l+1
insert @re select a.id,@l
from 表 a join @re b on a.上级id=b.id and b.level=@l-1
end
return
end
go
--调用函数进行查询
select a.* from 表 a join f_id(35) b on a.id=b.id
- SQL 递归查询
- SQL 递归查询
- SQL递归查询
- sql 递归查询
- SQL Server 递归查询
- SQL递归查询
- SQL递归查询函数
- SQL递归查询数据
- Sql 递归查询
- sql递归查询问题
- SQL递归查询函数
- SQL递归查询部门
- Sql 2005 递归查询
- SQL递归查询数据
- sql递归查询
- sql 递归查询
- sql递归查询问题
- 总计sql 递归查询
- java调用c++动态库
- InitializeCriticalSectionAndSpinCount()
- 表的连接
- Oracle 中的exception——(Raise)
- 收集SQLite中的时间日期函数
- Sql 递归查询
- [C++对象模型][2]指针与引用
- SQL研究-相似的数据类型
- Document 对象的常用方法
- 条件表达式求值
- C文件操作之fread,fwrite函数
- 如何穿越你?两个局域网
- 20岁拼体力,30岁拼专业,40岁拼人脉
- spring2.5 最详细的注释讲解