I m using the MPTT (modised preorder Gang transersal) model tostor data in mySQL table. (MPTT模型:另一个说明是 封套式)。 我的问题是:是否有任何人 figure清树 que果? 我只能按标签填写ER,但结果将按标签分类,不尊重树木的子点或深度。
这里有一个例子,即我用来找回一个任意的 no树,每个 no子深度:
SELECT node.id, (COUNT(parent.id) - (sub_tree.depth + 1)) AS depth
FROM person AS node,
person AS parent,
person AS sub_parent, (
SELECT node.id, (COUNT(parent.id) - 1) AS depth
FROM person AS node,
person AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt
AND node.id = 1 // that s my root object
GROUP BY node.id, node.lft
ORDER BY node.lft
) AS sub_tree
WHERE node.lft BETWEEN parent.lft AND parent.rgt
AND node.lft BETWEEN sub_parent.lft AND sub_parent.rgt
AND sub_parent.id = sub_tree.id
GROUP BY node.id
ORDER BY node.lft
http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/"rel=“nofollow noretinger” http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/。
当然,这总是按其位置在封套中订购物品。 如果我想要通过、说是最后的Name或账户或城镇来命令他们呢? 能否用我的SQL做,或者你们的民间人士认为,我不得不用我的描述语言对结果进行分类?