作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
在向树中插入新节点时,如何填充闭包表的深度/长度列?
ancestor 和 descendant 中的值是来自另一个表的 ID,表示要以树结构排列的页面。
关闭表:
ancestor descendant depth
1 1 0
1 2 1
1 3 1
1 4 1
2 2 0
3 3 0
4 4 0
这将正确插入祖先和后代,但我不确定如何填充深度列插入查询:
INSERT INTO closure_tree_path (ancestor, descendant)
SELECT ancestor, '{$node_id}' FROM closure_tree_path
WHERE descendant = '{$parent_id}'
UNION ALL SELECT '{$node_id}', '{$node_id}';
解决此问题的最佳方法是什么?非常感谢!
最佳答案
将 depth+1 添加到第一个 SELECT。
INSERT INTO closure_tree_path (ancestor, descendant, depth)
SELECT ancestor, '{$node_id}', depth+1 FROM closure_tree_path
WHERE descendant = '{$parent_id}'
UNION ALL SELECT '{$node_id}', '{$node_id}', 0;
关于php - 深入 MYSQL 和闭包表树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23030755/
我正在尝试添加一个新的后代,但很难实现它,它显示了一些错误,如果您能花时间回顾一下我迄今为止所做的事情,我将不胜感激。 这里 Controller public function index() {
我目前正在做一个 PoC 并面临闭包表的问题。我正在使用 Saiku CE,数据库是 postgres。一切正常,直到我添加一个闭包表。如果我删除闭包表层次结构,我不会收到任何错误。如果保留它,我会收
我有一组在 SQL Server 数据库中使用的分层数据。数据存储时使用 guid 作为主键,使用 ParentGuid 作为指向对象直接父对象的外键。我最常通过 WebApi 项目中的 Entity
我是一名优秀的程序员,十分优秀!