How many times each node collaborated with other nodes


(Mehdi Ajroud) #1

All what I need is knowing how many times each node collaborated with other nodes , I found this example and I followed it .
I runned this query :

MATCH (n:Attributaires)-[r:CollaborateWith]->(m:Attributaires)
With distinct n.id as Attributaires , size((n)-->(m)) AS NumberOfRelations , m.id AS Collaborators
RETURN Attributaires , NumberOfRelations , Collaborators

But I am getting the same value for all "NumberOfRelations" which is "1" .
Anyone has a solution and could help please ?


(Michael McKenzie) #2

Based on the example you reference your issue my be with size((n)-->(m)).

In the example, @Benoit uses size((n)-->()). In this example leaving the second node "emtpy" () lets you count all of those that are connected. However, in your example, using (m) means you are only counting the relationships between (m) and (n). Unless you have multiple relationships connecting these nodes, you will always get "1".

Try using

MATCH (n:Attributaires)-[r:CollaborateWith]->(m:Attributaires)
With distinct n.id as Attributaires , size((n)-->()) AS NumberOfRelations , m.id AS Collaborators
RETURN Attributaires , NumberOfRelations , Collaborators

(Bratanic Tomaz) #3

I think you can simplify you query:

MATCH (n:Attributaires)-[r:CollaborateWith]->(m:Attributaires)
WITH n.id as Attributaires , m.id AS Collaborators, count(*) AS NumberOfRelations 
RETURN Attributaires , NumberOfRelations , Collaborators

(Mehdi Ajroud) #4

This query give me the same results . But @mckenzma query worked :)