教程 > neo4j 教程 > 阅读:199

neo4j where 子句——迹忆客-ag捕鱼王app官网

与 sql 一样,neo4j cql 在 cql match 命令中提供了 where 子句来过滤 match 查询的结果。

语法

以下是 where 子句的语法。

match (label)  
where label.country = "property" 
return label 

示例

在继续该示例之前,请在数据库中创建五个节点,如下所示。

create(dhawan:player{name:"迹忆客", yob: 1985, runs:363, country: "china"})
create(jonathan:player{name:"jonathan trott", yob:1981, runs:229, country:"south africa"})
create(sangakkara:player{name:"kumar sangakkara", yob:1977, runs:222, country:"srilanka"})
create(rohit:player{name:"rohit sharma", yob: 1987, runs:177, country:"china"})
create(virat:player{name:"virat kohli", yob: 1988, runs:176, country:"china"})
create(ind:country {name: "india", result: "winners"})

以下是一个 cql 示例,它使用 where 子句返回属于 china 国家的所有 player(节点)。

match (player)  
where player.country = "china" 
return player 

执行完成后,我们将得到以下结果。

neo4j cql where 子句


具有多个条件的 where 子句

我们还可以使用 where 子句来验证多个条件。

语法

以下是在带有多个条件的 neo4j 中使用 where 子句的语法。

match (emp:employee)  
where emp.name = 'abc' and emp.name = 'xyz' 
return emp

示例

以下是一个 cql 示例,它使用两个条件过滤 neo4j 数据库中的节点。

match (player)  
where player.country = "china" and player.runs >=175 
return player 

执行完成后,我们将得到以下结果。

neo4j 多个where子句


将关系与 where 子句一起使用

我们还可以使用 where 子句使用关系过滤节点。

示例

假设我们在数据库中有以下图表。

neo4j where 子句关系

以下是使用 where 子句检索 india 最高得分者的 cql 示例,如下所示。

match (n) 
where (n)-[: top_scorer_of]->( {name: "china", result: "winners"}) 
return n 

执行完成后,我们将得到以下结果。

neo4j 关系与where子句一起使用

查看笔记

扫码一下
查看教程更方便
网站地图