【发布时间】:2014-04-12 13:03:35
【问题描述】:
在向树中插入新节点时,我将如何填充闭包表的深度/长度列?
祖先和后代中的值是来自另一个表的 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}';
解决此问题的最佳方法是什么?非常感谢!
【问题讨论】:
标签: php mysql transitive-closure-table