嵌套组DB2检索单一路径

我已经习惯了使用嵌套组在mysql和检索我通常会使用以下的单一路径:嵌套组DB2检索单一路径

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列表中的DEPTH或表达式无效。 错误代码:-122

如何从db2返回嵌套的设置路径?

回答:

在最后一组的,请尝试使用

GROUP BY node.treeID, 

node.name,

node.lft,

node.rgt HAVING (COUNT(parent.name) - (sub_tree.depth + 1)) = 1

以上是 嵌套组DB2检索单一路径 的全部内容, 来源链接: utcz.com/qa/266617.html

回到顶部