简体   繁体   English

基于和关系属性数组的CYPHER查询

[英]CYPHER query based on sum relationship property array

In my graph, relationships have a property named list .在我的图中,关系有一个名为list的属性。 list is an array of int. list是一个 int 数组。

It looks like this:它看起来像这样:

(head:Node)-[r:RELATIONSHIP {list:...}]->(tail:Node)

I'd like to query all tails in the graph, where the sum of list is > 0.我想查询图中的所有尾部,其中列表的总和 > 0。

Intuitively, I would do:直觉上,我会这样做:

MATCH (:Node)-[r:RELATIONSHIP]->(tail:Node)
WHERE sum(r.list) > 0
RETURN tail

This does not work unfortunately.不幸的是,这不起作用。 It throws an error.它抛出一个错误。 How can I write this query?我该如何编写此查询? Thanks谢谢

This should work for you:这应该适合你:

MATCH (:Node)-[r:RELATIONSHIP]->(tail:Node)
WHERE REDUCE(s = 0, v IN r.list | s + v) > 0
RETURN tail

I think this will do what you want我认为这会做你想做的

MATCH p=(n1:Node)-[:RELATIONSHIP*2..2]->(n2:Node) with n1 as head, n2 as tail, REDUCE(totalScore = 0.0, r in relationships(p) | totalScore + toFloat(r.score)) as score where score>1.99 return head.name, tail.name, score匹配 p=(n1:Node)-[:RELATIONSHIP*2..2]->(n2:Node) 以 n1 作为头部,n2 作为尾部,减少(totalScore = 0.0,r in关系(p)| totalScore + toFloat (r.score)) 作为 score 其中 score>1.99 返回 head.name, tail.name, score

Notes: In my example I'm specifying a fixed path length of 2, so that I could check the total scores easily... If you graph has bidirectional relationships or loops, know that head=tail is possible...注意:在我的示例中,我将固定路径长度指定为 2,以便我可以轻松检查总分...如果您的图形具有双向关系或循环,请知道 head=tail 是可能的...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM