首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在neo4j中显示所有节点以及两个节点之间的关系?

如何在neo4j中显示所有节点以及两个节点之间的关系?
EN

Stack Overflow用户
提问于 2021-01-02 13:29:15
回答 1查看 106关注 0票数 0

创建了Year和Month节点,并将其连接到Employee节点。这是Cypher:

代码语言:javascript
运行
复制
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,我想在这里显示两个员工之间的关系(两个员工是否会作为通用属性名字、姓氏、月、年等)。

提前感谢

EN

回答 1

Stack Overflow用户

发布于 2021-01-02 14:47:55

使用此查询,您可以获得两个节点之间的所有关系

代码语言:javascript
运行
复制
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{.*})}}

通过公共属性获取员工:

代码语言:javascript
运行
复制
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相似的其他员工。例如,我在一家公司工作(我的年龄、地点、加入数据的年份),我想知道公司中有类似关系的员工,比如年龄、入职年份、入职月份、地点等。

下面的查询应该可以工作

代码语言:javascript
运行
复制
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个

获取与两个或多个节点相关的所有公共节点的计数

代码语言:javascript
运行
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65536295

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档