Neo4j——哪个联邦州的委员会成员最多?

Neo4j——哪个联邦州的委员会成员最多?,neo4j,cypher,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 c

我是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
...      ...
如果我理解正确,输出告诉我每个
州的所有
立法者
和所有
委员会
节点之间有多少关系

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

输出的东西:

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

您可以尝试使用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

非常感谢你。这正是我需要的。我不知道你能像那样使用distinct。我尝试使用distinct作为回报,但这并没有改变输出。