Neo4j - 哪个联邦州在大多数委员会中都有成员?

时间:2018-01-08 19:25:38

标签: neo4j cypher

我是Neo4j的新手,正在学习基础知识。到目前为止,我已经成功地将其结合在一起:

MATCH (l:Legislator)-[:REPRESENTS]->(s:State)
MATCH (l)-[:SERVES_ON]->(c:Committee)
WITH s.code as states, count(c) as committees
return states, committees
order by committees DESC

此查询为我提供了以下输出:

s.code   committees
"CA"     90
"TX"     70
"NY"     51
"FL"     43
"PA"     36
"IL"     35
...      ...

如果我理解正确,输出会告诉我每个Legislator

中所有Committee和所有State个节点之间有多少关系

我如何更改查询以便获取每个州成员所在的唯一委员会的数量?

可输出的东西:

s.code   committees
"NY"     29
"TX"     27
"CA"     25
...      ...

1 个答案:

答案 0 :(得分:1)

您可以尝试使用distinct:

MATCH (l:Legislator)-[:REPRESENTS]->(s:State) 
MATCH (l)-[:SERVES_ON]->(c:Committee)
WITH s.code as states, count(distinct c) as committees
return states, committees
order by committees DESC