簡體   English   中英

如何顯示 neo4j 中的所有節點和兩個節點之間的關系?

[英]How can i display the all nodes and relationships between two nodes in neo4j?

創建 Year 和 Month 節點並將它們連接到 Employee 節點。 這是 Cypher:

MERGE (y:Year {year:toInteger(line.YearofJoining)})
MERGE (m:Month {month:line.MonthNamofJoining)})
MERGE (y)-[:MONTH]->(m)

MERGE (a:Employee {empid:line.EmpID, firstname:line.FirstName, lastname:line.LastName, 
gender:line.Gender})
MERGE (m)-[:EMPLOYEE]->(a)

如何顯示兩個節點之間的節點和關系? 例如,如果我 select 有兩個不同的員工 id,這里我想顯示兩個員工之間的關系是什么(將兩個員工作為共同屬性名、姓、月、年等)

提前致謝

使用此查詢,您可以獲得兩個節點之間的所有關系

MATCH (n1)-[r]->(n2) 
RETURN {type: type(r), nodes: {n1: n1{.*}, n2: n2{.*}}}

OR

MATCH (n1)-[r]->(n2) 
RETURN {type: type(r), nodes: {n1: collect(distinct n1{.*}), n2: collect(distinct n2{.*})}}

通過公共屬性獲取員工:

MATCH (e:Employee)-[]-(m:Month) 
return {
  month: m.month, // You can replace it with any property you want to group for example "gender: e.gender"
  employees: collect(distinct e{.*})
} as byMonth

編輯

如何知道與給定 Employee id 相似的其他員工。 例如,我在一家公司工作(我的年齡、位置、加入年份作為數據),我想知道公司中具有相似關系的員工,例如相同年齡、加入年份、加入月份、位置等.w.r.t 給我

下面的查詢應該工作

match (employee:Employee) where employee.empid= 1
optional match (employee)-[:EMPLOYEE]-(month:Month{month: 10})-[:EMPLOYEE]-(other:Employee) 
optional match (other) where other.monthOfJoining = employee.monthOfJoining or other.yearOfJoining = employee.yearOfJoining or other.age = employee.age
return employee, other

編輯 2

獲取與兩個或多個節點相關的所有公共節點的計數

MATCH (node1:Employee)-->(r)<--(node2:Employee)

with count(r) as maxCountRelation, node1{.*} as e1, node2{.*} as e2

return {commonRelation: maxCountRelation, employees: collect(distinct e1)+collect(distinct e2)} as result order by result.commonRelation desc limit 1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM