SQLserver2008使用表达式递归查询
2024-10-21 12:35:10
--由父项递归下级
with cte(id,parentid,text) as
(
--父项
select id,parentid,text from treeview where parentid = 450
union all
--递归结果集中的下级
select t.id,t.parentid,t.text from treeview as t
inner join cte as c
on t.parentid = c.id
)
select id,parentid,text from cte
---------------------
--由子级递归父项
with cte(id,parentid,text) as
(
--下级父项
select id,parentid,text from treeview where id = 450
union all
--递归结果集中的父项
select t.id,t.parentid,t.text from treeview as t
inner join cte as c
on t.id = c.parentid
)
select id,parentid,text from cte
最新文章
- linux 添加 service 服务并自动添加 chkconfig 启动级别
- 解决 connect to host github.com port 22 operation timed out
- ajax和json对象
- ASP.NET 5 (vNext) 理解和概述
- 安卓第十三天笔记-服务(Service)
- UVALive 6093 Emergency Room --优先队列实现的模拟
- Wall---hdu1348(求凸包周长 模板)
- 从原理上搞定编码-- Base64编码
- Web开发——Http协议剖析
- 如何计算ModBus超时时间?
- HDU 1080 Human Gene Functions--DP--(变形最长公共子)
- restful restAPI 的定义方式
- WebSocketSharp 的使用
- mysql数据库的查询,添加,删除,还原,备份
- PostgreSQL分页
- [转] 前后端分手大师——MVVM 模式
- SQLite 知识摘要 --- 事务
- Navicat Premium
- C++“隐藏实现,开放接口”的实现方案
- Applese的回文串-dfs
热门文章
- contain与compareDocumentPosition
- Django QuerySet API
- Arcgis Javascript API 开发笔记
- tcp连接的建立与释放
- segment fault本质
- kolla all-in-one 安装
- 关于angularJS的$watch的 一些小用法
- html5适应屏幕的方案
- windows平台下安装Beautiful Soup
- Prism开发人员指南5-WPF开发 Developer's Guide to Microsoft Prism Library 5.0 for WPF (英汉对照版)