我习惯于在 mysql 中使用嵌套集并检索单个路径,我通常会使用以下内容:
SELECT node.treeID,
node.name,
node.lft,
node.rgt,
(COUNT(parent.name) - (sub_tree.depth + 1)) AS depth
FROM docsTree AS node,
docsTree AS parent,
docsTree AS sub_parent,
( SELECT node.name,
(COUNT(parent.name) - 1) AS depth
FROM docsTree AS node,
docsTree AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt
AND node.treeID = :requestedNode
GROUP BY node.treeID,
node.name,
node.lft,
node.rgt
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.name = sub_tree.name
GROUP BY node.treeID,
node.name,
node.lft,
node.rgt HAVING depth = 1
ORDER BY node.lft
现在我需要在 db2 中做同样的事情,但上面的查询给了我以下错误:
错误:SELECT 或 HAVING 子句中的列引用无效,因为它不是分组列;或者 GROUP BY 子句中的列引用无效。
[SQL0122] SELECT 列表中的列深度或表达式无效。错误代码:-122
如何从 db2 返回嵌套的设置路径?