【问题标题】:How can I calculate the average number of relationships each node has in neo4j?如何计算每个节点在 neo4j 中的平均关系数?
【发布时间】:2020-04-10 20:38:30
【问题描述】:

一直在寻找每个节点的平均关系数。我知道如何找到节点的数量和关系的总数。但我不能将它们组合成一个查询。请帮忙

【问题讨论】:

    标签: neo4j divide


    【解决方案1】:

    您可以使用这种方法。这是为了获取所有节点的此信息,无论标签如何:

    MATCH (n)
    WITH n, size((n)--()) as relCount
    RETURN avg(relCount) as averageRelCount
    

    如果除了总节点和总关系之外,您还尝试返回此信息,那么您应该阅读getting fast counts from the counts store 上的这篇知识库文章。它可以为您提供这些总数,但它无法为您提供上述的平均 rel 计数。

    您可以通过在查询的早期使用计数存储和最后的平均关系部分来组合它们。

    如果您使用 APOC 程序从商店中选择您想要的计数,以下是您可以使用的方法:

    CALL apoc.meta.stats() YIELD nodeCount, relCount as totalRelCount
    MATCH (n)
    WITH n, size((n)--()) as relCount, nodeCount, totalRelCount
    RETURN avg(relCount) as averageRelCount, nodeCount, totalRelCount
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多