[英]Can graph database query “nodes that a given node has no relationship with”?
[英]Nodes with same relation to a third node in a graph database
我正在關注Neo4J在線教程,並在使用查詢工具嘗試此查詢時遇到一個問題:
match (a:Person)-[:ACTED_IN|:DIRECTED]->()<-[:ACTED_IN|:DIRECTED]-(b:Person)
return a,b;
我期望返回的兩個對中的一個在兩個標識符中都具有相同的Person,但那沒有發生。 有人可以解釋一下為什么嗎? match子句是否在使用的不同標識符中排除重復的元素?
更新:這個問題在Neo4J在線教程的“第3課-添加與Cypher的關系,更多”中出現,我在上面提出了我提到的查詢。 我將查詢優化為以下查詢,以便更直接地關注我的問題:
MATCH (a:Person {name:"Keanu Reeves"})-[:ACTED_IN]->()<-[:ACTED_IN]-(b)
RETURN a,b;
結果:
|---------------|--------------------|
| a | b |
|---------------|--------------------|
| Keanu Reeves | Carrie-Anne Moss |
| Keanu Reeves | Laurence Fishburne |
| Keanu Reeves | Hugo Weaving |
| Keanu Reeves | Brooke Langton |
| Keanu Reeves | Gene Hackman |
| Keanu Reeves | Orlando Jones |
|------------------------------------|
那么,為什么在a和b中沒有與Keanu Reeves發生爭執? 他不應該同時滿足兩種關系:ACTED_IN嗎?
我會檢查您的數據樣本。 您的查詢看起來對我來說很好。 我用一個簡單的數據集進行了復制,這里的驗證是它確實會產生與您想要的對類似的對。
喬飾演《 Some Flick》
neo4j-sh (?)$ create (p:Person {name:"Joe"})-[:ACTED_IN]->(m:Movie {name:"Some Flick"});
+-------------------+
| No data returned. |
+-------------------+
Nodes created: 2
Relationships created: 1
Properties set: 2
Labels added: 2
14 ms
但是喬是如此多才多藝,他還執導過《 Some Flick》。
neo4j-sh (?)$ match (p:Person {name: "Joe"}), (m:Movie {name: "Some Flick"}) create p-[:DIRECTED]->m;
+-------------------+
| No data returned. |
+-------------------+
Relationships created: 2
23 ms
那么,我們認識的演員/導演對是誰?
neo4j-sh (?)$ match (a:Person)-[:ACTED_IN|:DIRECTED]->()<-[:ACTED_IN|:DIRECTED]-(b:Person)
> return a,b;
+-----------------------------------------------------+
| a | b |
+-----------------------------------------------------+
| Node[222128]{name:"Joe"} | Node[222128]{name:"Joe"} |
| Node[222128]{name:"Joe"} | Node[222128]{name:"Joe"} |
+-----------------------------------------------------+
2 rows
50 ms
當然是喬。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.