获取cypher查询中没有关系的多个节点的计数

时间:2016-06-24 04:22:33

标签: neo4j cypher

如何获取多个节点的计数。

MATCH (n1:node1) 
MATCH (n2:node2) 
MATCH (n3:node3) where n3.status = "active" 
return count(n1) as countOfNode1,
count(n2) as countOfNode2,
count(n3) as countOfNode3

此查询返回重复的结果

countOfNode1 = 0
countOfNode2 = 0
countOfNode3 = 0

真实计数

countOfNode1 = 0
countOfNode2 = 3
countOfNode3 = 1

怎么做?

使用' distinct'也没有解决问题。 鉴于:

return count(distinct n1) as countOfNode1,
count(distinct n2) as countOfNode2,
count(distinct n3) as countOfNode3

1 个答案:

答案 0 :(得分:0)

我正在考虑的一种可能性是

MATCH (n1:node1) WITH count(n1) as countOfNode1
MATCH (n2:node2) WITH count(n2) as countOfNode2 
MATCH (n3:node3) where n3.status = "active"  WITH count(n3) as countOfNode3
return countOfNode1,
countOfNode2,
countOfNode3

或者

MATCH (n1:node1), (n2:node2),(n3:node3 {status:"active"} )
return count(n1) as countOfNode1,
count(n2) as countOfNode2,
count(n3) as countOfNode3