返回一个MATCH语句的多个关系计数 [英] Return multiple relationship counts for one MATCH statement
本文介绍了返回一个MATCH语句的多个关系计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想做这样的事情:
MATCH (p:person)-[a:UPVOTED]->(t:topic),(p:person)-[b:DOWNVOTED]->(t:topic),(p:person)-[c:FLAGGED]->(t:topic) WHERE ID(t)=4 RETURN COUNT(a),COUNT(b),COUNT(c)
..但是当我应该得到2、1、1时,我得到了全部0个计数
..but I get all 0 counts when I should get 2, 1, 1
推荐答案
更好的解决方案是使用size
,它可以大大提高查询的性能:
A better solution is to use size
which improve drastically the performance of the query :
MATCH (t:Topic)
WHERE id(t) = 4
RETURN size((t)<-[:DOWNVOTED]-(:Person)) as downvoted,
size((t)<-[:UPVOTED]-(:Person)) as upvoted,
size((t)<-[:FLAGGED]-(:Person)) as flagged
如果您确定关系中的其他节点始终标有Person,则可以将它们从查询中删除,这样会再次更快
If you are sure that the other nodes on the relationships are always labelled with Person, you can remove them from the query and it will be a bit faster again
这篇关于返回一个MATCH语句的多个关系计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文