关于nested sets树
来源:互联网 发布:西安爱知中学中考 编辑:程序博客网 时间:2024/04/29 09:51
原文:http://www.eastphp.com/2052/
作者在检索子树的深度时用的sql语句有点复杂,几个join,还有个子查询。
我的SQL是这样,只用二个join。
select s.name,count(*)-1 as depth from nested_category as n,nested_category as s
where n.lft between 10 and 19
and s.lft between n.lft and n.rgt group by s.name
注意上面的10,19是某条记录的左右值(这二个值通常不难获得)。同样可以检索整树,只要改变左右值为根的左右值。
于是,检索节点的直接子节点也将方便。
select s.name,count(*)-1 as depth from nested_category as n,nested_category as s
where n.lft between 10 and 19
and s.lft between n.lft and n.rgt group by s.name
having depth=1
作者在检索子树的深度时用的sql语句有点复杂,几个join,还有个子查询。
我的SQL是这样,只用二个join。
select s.name,count(*)-1 as depth from nested_category as n,nested_category as s
where n.lft between 10 and 19
and s.lft between n.lft and n.rgt group by s.name
注意上面的10,19是某条记录的左右值(这二个值通常不难获得)。同样可以检索整树,只要改变左右值为根的左右值。
于是,检索节点的直接子节点也将方便。
select s.name,count(*)-1 as depth from nested_category as n,nested_category as s
where n.lft between 10 and 19
and s.lft between n.lft and n.rgt group by s.name
having depth=1
- 关于nested sets树
- Model Tree Structures with Nested Sets
- 关于 grouping sets 学习
- Sets
- 关于Eclipse中Working Sets的问题
- 关于nested transactions not supported的问题
- URAL1987. Nested Segments 线段树
- 关于rollup,cube,grouping sets的个人理解
- 关于lists:member 与 sets:is_element 性能比较
- 关于 Oracle GoldenGate Core Product Patch Sets 的列表
- 关于SVN弹出“update change sets for svnstatussubscriber......”的处理
- 吴恩达关于dev / test sets的形象解释
- UVA 11488,Hyper Prefix Sets,Trie树
- UVa11488-Hyper Prefix Sets(trie树)
- Hyper Prefix Sets - UVa 11488 Trie树
- uva 11488 - Hyper Prefix Sets(字典树)
- uva11488 Hyper Prefix Sets(Trie树)
- UVA 11488 Hyper Prefix Sets 字典树
- java类——汉字转拼音
- js 模拟下拉框
- FckEditor自定义工具条
- java类——使用javax.xml创建xml文件
- 冒泡排序
- 关于nested sets树
- instr的使用
- String被误解
- FMode使用入门
- 云计算-cloud computing
- 启程
- mysql查询优化之基于索引的排序
- blog
- 绕过安全软件挂钩SSDT的检测