MATCH (p:Person {name: 'Eminem'})-[:ACTED_IN*2]-(others:Person) RETURN others.name
使用 ACTED_IN 关系检索与 Eminem 恰好四跳距离的所有 Person 节点。
MATCH (p:Person {name: 'Eminem'})-[:ACTED_IN*4]-(others:Person) RETURN others.name
使用 ACTED_IN 关系检索距离 Eminem 最多四跳的所有 Person 节点。
MATCH (p:Person {name: 'Eminem'})-[:ACTED_IN*1..4]-(others:Person) RETURN others.name
找出图中节点彼此“接近”的程度。
参数
查询的范围变量(类似于Oracle中的定义变量)
使用 WITH 子句定义和初始化要在查询中使用的变量。
WITH 'Tom Hanks' AS actorName MATCH (p:Person)-[:ACTED_IN]->(m:Movie) WHERE p.name = actorName RETURN m.title AS movies
使用WITH子句作用域变量
WITH 'toy story' AS mt, 'Tom Hanks' AS actorName MATCH (p:Person)-[:ACTED_IN]->(m:Movie) WITH m, toLower(m.title) AS movieTitle WHERE p.name = actorName AND movieTitle CONTAINS mt RETURN m.title AS movies, movieTitle
如果您要删除第二WITH个子句中的 m,查询将无法编译。(返回节点的属性则在 WITH 中要定义节点)
限制结果
Return 后加 Limit
WITH 'Tom Hanks' AS theActor MATCH (p:Person)-[:ACTED_IN]->(m:Movie) WHERE p.name = theActor RETURN m.title AS movies LIMIT 2
WHERE 后使用 WITH 子句
WITH 'Tom Hanks' AS theActor MATCH (p:Person)-[:ACTED_IN]->(m:Movie) WHERE p.name = theActor WITH m ORDER BY m.year LIMIT 2 RETURN m.title AS movies
WITH子句中嵌套子句
MATCH (n:Movie) WHERE n.imdbRating IS NOT NULL AND n.poster IS NOT NULL WITH n { .title, .year, .languages, .plot, .poster, .imdbRating, directors: [ (n)<-[:DIRECTED]-(d) | d { tmdbId:d.imdbId, .name } ]} ORDER BY n.imdbRating DESC LIMIT 4 RETURN collect(n)
WITH 后已经聚合属性值,RETURN再使用别名用反引号
MATCH (p:Person)-[:ACTED_IN]->(m:Movie)<-[r:RATED]-(:User) WHERE p.name = 'Tom Hanks' WITH m, avg(r.rating) AS avgRating RETURN m.title AS Movie, avg Rating AS `AverageRating` ORDER BY avgRating DESC
使用 UNWIND 子句定义使用的变量
为列表的每一列返回一行(列转行)
MATCH (m:Movie)-[:ACTED_IN]-(a:Actor) WHERE a.name = 'Tom Hanks' UNWIND m.languages AS lang RETURN m.title AS movie,m.languages AS languages,lang AS language
MATCH (m:Movie) UNWIND m.countries AS country WITH m, trim(country) AS trimmedCountry WITH trimmedCountry, collect(m.title) AS movies RETURN trimmedCountry, size(movies)
1.3 Hamilton 系统的辛几何算法 经典力学有三种等价的 “数学形式” 体系: Newton 体系、Lagrange 体系和 Hamilton 体系, 其中 Hamilton 体系具有对称的形式且能应用于较广泛的物理现象, 故它一直是物理学理论研究的数学工具. Hamilton 体系的一个重要特性是稳定性, 它在几何上…