创建了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)
如何显示节点以及两个节点之间的关系?例如,如果我选择了两个不同的员工id,我想在这里显示两个员工之间的关系(两个员工是否会作为通用属性名字、姓氏、月、年等)。
提前感谢
发布于 2021-01-02 14:47:55
使用此查询,您可以获得两个节点之间的所有关系
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
编辑
如何知道与给定员工id相似的其他员工。例如,我在一家公司工作(我的年龄、地点、加入数据的年份),我想知道公司中有类似关系的员工,比如年龄、入职年份、入职月份、地点等。
下面的查询应该可以工作
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
https://stackoverflow.com/questions/65536295
复制相似问题