Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-28-2021 09:45 AM
I want to count the number of common relations shared by two employee nodes. I will attach my query
// Employee data
:auto USING PERIODIC COMMIT 5
LOAD CSV WITH HEADERS FROM 'file:///y.csv' AS line
MERGE (a:Employee {empid:line.EmpID})
ON CREATE SET a.firstname = line.FirstName, a.lastname = line.LastName
MERGE (g:Gender{gender:line.Gender})
Merge (a)-[:GENDER]-(g)
MERGE (ag:Age {age:toInteger(line.AgeinYrs)})
MERGE (a)-[:AGE]-(ag)
MERGE (y:Year {year:toInteger(line.YearofJoining)})
Merge (a)-[:YEAR_OF_JOINING]-(y)
MERGE (m:Month {month:line.MonthNamofJoining})
merge (a)-[:JOINING_MONTH]-(m)
Merge (c:City {city:line.City})
Merge (a)-[:CITY]-(c)
Merge (p:Pincode{pincode:line.PinCode})
Merge (a)-[:PINCODE]-(p)
Merge (C:County {county:line.County})
Merge (a)-[:COUNTY]-(C)
Merge (r:Region {region:line.Region})
Merge (a)-[:REGION]-(r)
Merge (s:State{state:line.State})
Merge (a)-[:STATE]-(s)
return a,y,m,ag,p,C,r,s,g limit 25
//Relation between two employees
MATCH (a:Employee)-[r]->(b)
where a.empid in ['789773','158108']
return a,b,r
1)How can I count common relationships shared by these two nodes
2)How can I count most no of relationships shared by any two nodes from whole data.
01-28-2021 10:59 AM
You can return the whole path too with the RETURN path clause instead
Not sure what you mean for the question 2
01-29-2021 08:17 AM
I want to return employees who had the highest no of relationships shared between them.
for example [employee 1 & employee 2 as four common relations] and [employee 3 & employee2] as five common relations. so here the highest relations exist between employee2 & employee3. so I want to return employee 3 and employee 2 count.
01-28-2021 12:24 PM
Try this for #2:
MATCH (d)-[r]-(a)
WITH labels(d) as lbl, type(r) as rels, count(r) as Cnt, labels(a) as lbl1
RETURN lbl, rels, Cnt, lbl1 order by Cnt desc
All the sessions of the conference are now available online