简体   繁体   中英

How to find the most connected node of particular relationship type in neo4j using cypher query?

Can some one help me to find the most connected node of particular relationship type in neo4j using cypher query.

Suppose I have

Node1 Node2 Relationship
A B follows
A C follows
B D follows

A D follows

Here Node D is the most connected node.of particular relationship type "Follows" .so how to find this node using cypher query?

Thanks in Advance


(Edit): i found my answer tnx Martin Preusse

  MATCH (n)<-[r:FOLLOWS]-() RETURN n, count(r) AS num ORDER BY num desc 

Try this if the direction of the relationship matters (will only return A and B ):

MATCH (n)-[r:follows]->()
RETURN n, count(r) AS num
ORDER BY num

Or this if you don't need the direction (ie the node D will be returned as well):

MATCH (n)-[r:follows]-()
RETURN n, count(DISTINCT r) AS num
ORDER BY num

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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