【问题标题】:neo4j counting relations of multiple nodesneo4j统计多个节点的关系
【发布时间】:2014-11-26 19:22:54
【问题描述】:

我在处理 neo4j 图,我写了这个查询

    match (rec:Recipe) , (rec1:Recipe) , (rec)-[r:ContainsIngredient]->() , (rec1)-       [r1:ContainsIngredient]->()  
where rec.name = "a" AND rec1.name = "b"
return  count(r) , count(r1)

它返回相同的值,虽然 Recipe("a") 有三个关系,Recipe("b") 有 5 个关系。 注意:我注意到它总是返回更大的值。

【问题讨论】:

    标签: neo4j cypher relationship


    【解决方案1】:

    您没有按配方名称分组。试试这个:

    MATCH (rec:Recipe)
    WHERE rec.name = "a" OR rec.name = "b"
    MATCH (rec)-[:ContainsIngredient]->()
    RETURN rec.name, COUNT(*)
    

    【讨论】:

    • 或者WHERE rec.name IN ['a','b']
    • 你也可以将两个匹配合并为一个
    猜你喜欢
    • 2014-08-27
    • 1970-01-01
    • 1970-01-01
    • 2015-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-24
    相关资源
    最近更新 更多