[英]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. 如果您找到每种类型汽车的min
和max
,然后直接匹配节点以获得最高和最低速度并连接它们,那该怎么办?
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.