简体   繁体   English

如何在具有共同属性的两个节点之间创建关系?

[英]How to create a relationship between two nodes with common properties?

I think I am asking this question right. 我想我正在问这个问题。 The data in my node looks like this: 我的节点中的数据如下所示:

Car      Speed
---      -----
Farrari  80
Corvette 92
Farrari  135
Corvette 129
Porche   78
Porche   150

I want to create a relationship called HIGH_SPEED between the two same cars with the highest speed and the lowest speed of the car. 我想在两辆相同的汽车之间建立一个名为HIGH_SPEED的关系,速度最快,车速最低。 So essentially relationship should look like this: 所以基本上关系应该是这样的:

                  ___________                        ___________
                 /           \                      /           \
                /             \    High Speed      /             \
               |  Car: Porche  |_________________\|  Car: Porche  |  
               |  Speed: 78    |                 /|  Speed: 150   |
                \             /                    \             /
                 \___________/                      \___________/

This is what I have got so far. 这是我到目前为止所得到的。 This creates an empty relationship. 这会创建一个空关系。

MATCH (c_max:CARS), (c_min:CARS)
with c_max.name as max_name, max(c_max.speed) as max_speed
   , c_min.name as min_name, min(c_min.speed) as min_speed
WHERE c_max.name = c_min.name
FOREACH (x IN max_name |
  FOREACH (y IN min_name |
    CREATE (x)-[:HIGH_SPEED]->(y)))

How about if you found the min and max for each type of car and then matched the nodes directly for the highest and the lowest speeds and connect them. 如果您找到每种类型汽车的minmax ,然后直接匹配节点以获得最高和最低速度并连接它们,那该怎么办?

match (c:CARS)
with c.name as type, min(c.score) as min_speed, max(c.score) as max_speed
match (c1:CARS {name: type, score: min_speed}), (c2:CARS {name: type, score: max_speed})
create (c1)-[:HIGH_SPEED]->(c2)
return c1, c2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用APOC在2个节点之间创建关系,其中节点的标签,属性和关系是可变的 - How to create a relationship between 2 nodes where the nodes' labels, properties and the relationship are variable using APOC 如何在图数据库中的节点之间创建两个关系 - How to create two relationship between nodes in graph DB 如何使用节点 ID 在两个现有节点之间创建关系? - How to create relationship between two existing nodes by using node id? 为一组节点创建每两个节点之间的关系 - Create relationship between each two nodes for a set of nodes 在STRUCTR.org中创建两个现有节点之间的关系 - Create relationship between two existing nodes in STRUCTR.org 如何使用C#Neo4jClient在两个节点之间创建关系? - How do I create a relationship between two nodes using C# Neo4jClient? 如何在两个节点之间的neo4j中创建关系? - How do I create a relationship in neo4j between two nodes? 如何基于父节点在两个随机节点之间创建关系? - How can I create a relationship between two random nodes based on parent node? 如何使用cypher在Neo4j中给出它们的属性来创建两个节点之间的关系 - How to use cypher to create relationship between two nodes given their attributes in Neo4j 如何基于匹配属性的条件创建与现有节点的关系 - How to create a relationship to existing nodes based on a condition of matching properties
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM