博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【原】Sql2005 实现递归
阅读量:4562 次
发布时间:2019-06-08

本文共 661 字,大约阅读时间需要 2 分钟。

2010-04-13 15:00

select * into t from

(
select 1 as id,'中国' as [name],0 as parentId union all
select 2,'江西',1 union all
select 3,'浙江',1 union all
select 4,'杭州',3 union all
select 5,'南昌',2 union all
select 6,'桐乡',4 union all
select 7,'桐炉',4 union all
select 8,'进贤',5 union all
select 9,'东湖区',5 union all
select 10,'建德',4
) as temp
--select * from t;
;

with tree(id,name,parentID) as--//括号内的内容也可以不要。相当于传递给方法的参数

(
select id,[name],parentID from t where [name] = '浙江'
union all
select t.id,t.[name],t.parentID from t inner join tree on t.parentID = tree.id
)

select * from tree

drop table t

参考:

转载于:https://www.cnblogs.com/qingyun163/archive/2012/02/23/2365594.html

你可能感兴趣的文章
编程迷茫时候看一看
查看>>
“ORA-00913: 值过多”、“ORA-00911: 无效字符”
查看>>
编程中的那些容易迷糊的小知识
查看>>
Sizzle前奏
查看>>
Paint Chain HDU - 3980(sg)
查看>>
Chales常用操作
查看>>
C++ 运算符重载<<
查看>>
windows镜像
查看>>
Flask 模板语法
查看>>
spark-2.2.0安装和部署——Spark集群学习日记
查看>>
ZOJ FatMouse' Trade 贪心
查看>>
音乐播放器
查看>>
SQL COOKBOOK (Ch.1-10)
查看>>
创建数组
查看>>
dict使用
查看>>
[转] 移动平台Html5的viewport使用经验
查看>>
ASP.NET MVC的帮助类HtmlHelper和UrlHelper
查看>>
《Python数据科学手册》第五章机器学习的笔记
查看>>
ubuntu16.04 配置爬虫环境
查看>>
Centos7,PHP7安装swoole
查看>>