将几个apoc.path.expand调用合并为一个

时间:2019-11-21 19:56:49

标签: neo4j cypher

我有几个密码调用,它们返回连接到我节点的特定类型(ABC)的节点数

MATCH (n {{ID:"{id}"}})
        call apoc.path.expand(n, "<", ">A", 1, 10) yield path as p
        return count(distinct nodes(p)[-1])
MATCH (n {{ID:"{id}"}})
        call apoc.path.expand(n, "<", ">B", 1, 10) yield path as p
        return count(distinct nodes(p)[-1])
MATCH (n {{ID:"{id}"}})
        call apoc.path.expand(n, "<", ">C", 1, 10) yield path as p
        return count(distinct nodes(p)[-1])

将这些呼叫进行3次非常浪费,我想知道是否可以将它们组合为一个,但仍然能获得全部三个的独特计数

1 个答案:

答案 0 :(得分:1)

这样的事情能为您完成吗?

MATCH (n {{ID:"{id}"}})
CALL apoc.path.expand(n, "<", ">A,>B,>C", 1, 10) yield path as p
RETURN labels(last(nodes(p)))[0] AS label, count(distinct nodes(p)[-1])