Neo4j-cypher语言

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Neo4j-cypher语言相关的知识,希望对你有一定的参考价值。

1、创建节点

CREATE (ee:Person { name: "Emil", from: "Sweden", klout: 99 });

2、查询节点

MATCH (ee:Person) WHERE ee.name = "Emil" RETURN ee;

3、创建节点的关系

MATCH (w:Person),(m:Student) where id(w)=1 and id(m)=2 create (w)-[:IS_STUDENT]->(m);

4、一起创建节点和关系

MATCH (ee:Person) WHERE ee.name = "Emil"
CREATE (js:Person { name: "Johan", from: "Sweden", learn: "surfing" }),
(ir:Person { name: "Ian", from: "England", title: "author" }),
(rvb:Person { name: "Rik", from: "Belgium", pet: "Orval" }),
(ally:Person { name: "Allison", from: "California", hobby: "surfing" }),
(ee)-[:KNOWS {since: 2001}]->(js),(ee)-[:KNOWS {rating: 5}]->(ir),
(js)-[:KNOWS]->(ir),(js)-[:KNOWS]->(rvb),
(ir)-[:KNOWS]->(js),(ir)-[:KNOWS]->(ally),
(rvb)-[:KNOWS]->(ally);

5、查询节点及关系

MATCH (ee:Person)-[:KNOWS]-(friends)
WHERE ee.name = "Emil" RETURN ee, friends

6、复杂查询节点及关系

MATCH (js:Person)-[:KNOWS]-()-[:KNOWS]-(surfer)
WHERE js.name = "Johan" AND surfer.hobby = "surfing"
RETURN DISTINCT surfer;

7、节点关系深度查询(0..1代表深度几级)

MATCH (js:Person)-[*0..1]-(m) RETURN js

8、MERGE(先查询,当不存在时创建)

MERGE(ee:Person{name:"Emil"})  CREATE (ee:Person { name: "Emil", from: "Sweden", klout: 99 });

9、删除

DELETE n, r(删除节点,带关系的删除不了)

DETACH DELETE n(删除节点,带关系的直接删除)

MATCH (n) DETACH DELETE n(删除所有)

 

以上是关于Neo4j-cypher语言的主要内容,如果未能解决你的问题,请参考以下文章

r语言index函数在哪个包

r语言赋值变量怎么输入?

r语言删除不相关属性

r 语言 怎么计算fdr

chatGPT对话R语言

什么是r语言