上一篇文章我们学习了Neo4j中的更新操作,今天我们学习一下Neo4j的查询。
说到查询我们就不得不提到Match关键字

Match

查询所有节点

Match (n:Role) return n

条件查询

Match(n:Role) where n.name="主角" return n

在条件查询的过程中我们经常会使用where关键字来进行过滤,有时候我们还可以使用到With关键字,With可以看成用于向后面的查询传递结果,将前面查询到返回值作为输入传递到后面去

MATCH (n:Role) with n as m where m.age>10 RETURN m.age

当然查询也可以查询一条路径

MATCH (n:Role)-[r:ACTION]->(m:Person) with n as m where m.age>10 RETURN m.age

Optional match

optional MATCH (n:Role)  where n.age>40  RETURN n.age

在这里插入图片描述
在这里插入图片描述

我们之前在查询Role时,如果查询不到会返回no changes,no records。但是如果我们使用Optional会返回一个null对象

distinct去重

MATCH (n:Role)  RETURN distinct n.age

在查询过程中,如果有重复数据,我们可以使用distinct去除重复数据

更多推荐