首页 > 解决方案 > 将多个 apoc.path.expand 调用合二为一

问题描述

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

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 次是浪费的,我想知道我是否可以将它们合并为一个,但仍然可以获得所有三个的不同计数

标签: neo4jcypher

解决方案


这样的事情可以为您完成吗?

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])

推荐阅读