MATCH p=()-[r:`包含`]->() where n.name="算法" return n neo4j中查找算法节点的包含关系怎么改正
时间: 2024-02-13 11:01:38 浏览: 28
首先,Cypher查询语句中要返回节点n,但是MATCH子句中并没有定义n,应该将其改为r。其次,WHERE子句中引用了n.name,应该将其改为r.name。最后,关系类型`包含`应该使用反引号(`)括起来,因为其中包含了中文字符。因此,正确的查询语句应该是:
```
MATCH (n)-[r:`包含`]->() WHERE r.name = "算法" RETURN n
```
这条语句会查找所有包含名为"算法"的节点的关系,然后返回这些关系的起始节点n。
相关问题
MATCH p=(n:person)-[r:`关系`]-(m) where n.name=aName RETURN p" ^.; nested exception is org.neo4j.ogm.exception.CypherException: Cypher execution failed with code 'Neo.ClientError.Statement.SyntaxError': Variable
这条Cypher查询语句中的变量aName没有定义。请确保aName已经被定义并且赋值了一个合法的字符串。如果aName是一个变量,请在查询之前先定义并给它赋值。如果aName是一个字符串,请将其用引号括起来,例如:
MATCH p=(n:person)-[r:`关系`]-(m) WHERE n.name='aName' RETURN p
Consider the following Neo4J Cypher CREATE command. CREATE (sue:Person {name:"Sue"}),(anna:Person {name:"Anna"}), (joe:Person {name:"Joe"}), (bob:Person {name:"Bob"}), (sue)-[:KNOWS]->(bob), (sue)-[:KNOWS]->(anna), (sue)-[:KNOWS]->(joe), (joe)-[:KNOWS]->(anna) a. Draw the property graph diagram that would result from executing the command. b. Write a Cypher query that reports the common friends of Anna and Joe. Report the query and the result of running it in the created database.
a. The property graph diagram resulting from executing the command is:
```
(sue)-[:KNOWS]->(bob)
(sue)-[:KNOWS]->(anna)
(sue)-[:KNOWS]->(joe)
(joe)-[:KNOWS]->(anna)
```
```
(sue) ---[:KNOWS]---> (bob)
|
|
[:KNOWS]|
|
V
(anna)
|
[:KNOWS]|
|
V
(joe)
```
b. The Cypher query that reports the common friends of Anna and Joe is:
```
MATCH (anna:Person)-[:KNOWS]->(friend:Person)<-[:KNOWS]-(joe:Person)
WHERE anna.name = 'Anna' AND joe.name = 'Joe'
RETURN friend.name
```
The result of running the query in the created database would be:
```
friend.name
-----------
Sue
```