![](/img/trans.png)
[英]How to create a relationship between 2 nodes where the nodes' labels, properties and the relationship are variable using APOC
[英]How to create a relationship between two nodes with common properties?
我想我正在問這個問題。 我的節點中的數據如下所示:
Car Speed
--- -----
Farrari 80
Corvette 92
Farrari 135
Corvette 129
Porche 78
Porche 150
我想在兩輛相同的汽車之間建立一個名為HIGH_SPEED的關系,速度最快,車速最低。 所以基本上關系應該是這樣的:
___________ ___________
/ \ / \
/ \ High Speed / \
| Car: Porche |_________________\| Car: Porche |
| Speed: 78 | /| Speed: 150 |
\ / \ /
\___________/ \___________/
這是我到目前為止所得到的。 這會創建一個空關系。
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)))
如果您找到每種類型汽車的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.