简体   繁体   English

Neo4j - 计算不同的节点

[英]Neo4j - Count distinct nodes

I have this kinds of relationships: 我有这种关系:

(:User)<-[:MENTIONS]-(:Tweet)-[:ABOUT]->(:Topic)

I would like to count all the users mentioned in the tweets regarding some topic. 我想统计推文中提到的有关某些主题的所有用户。

With the following query 使用以下查询

match (n:Topic)<--(t:Tweet)-[:MENTIONS]->(u:User) 
where n.name='politics'
return distinct count(u)

all I get is the relationships count. 我得到的只是关系计数。

What I would like to get is, instead, the number of users mentioned (without duplicates if a user is mentioned several times). 相反,我想要的是提到的用户数量(如果多次提到用户,则没有重复)。 How is that possible? 怎么可能?

Try putting distinct inside count function, this way: 尝试使用不同的内部count功能,这样:

match (n:Topic)<-[:ABOUT]-(t:Tweet)-[:MENTIONS]->(u:User) 
where n.name='politics'
return count(distinct u)

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

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