MATCH (xiyouji:Person) WHERE xiyouji.name="西游记" RETURN xiyouji
等同于如下查询
1
MATCH (xiyouji:Person {name:"西游记"}) RETURN xiyouji
使用正则匹配如下
1
MATCH (xiaolv:Person)-[r:ACTED_IN]->(xiyouji) WHERE xiaolv.name =~ "小+" OR "Neo" IN r.roles RETURN xiaolv,r,xiyouji
4.3 内置函数使用
使用NOT 排除关系
1 2 3
MATCH (p:Person)-[:ACTED_IN]->(m) WHERE NOT (p)-[:DIRECTED]->() RETURN p,m
内置函数的
1
MATCH (p:Person) RETURN p,p.name AS name, toUpper(p.name), coalesce(p.name, "n/a") AS nickname, { name: p.name, label: head(labels(p))} AS person
4.4 汇总信息
使用count
1 2
MATCH (:Person) RETURN count(*) AS people
使用
1
MATCH (actor:Person)-[:ACTED_IN]->(movie:Movie)<-[:DIRECTED]-(director:Person) RETURN actor, director, count(*) AS collacbotration
4.5 排序和分页
使用 limit 以及 skip 进行分页
1 2
MATCH (a:Person)-[:ACTED_IN]->(m:Movie) RETURN a, count(*) AS appearances ORDER BY appearances DESC LIMIT 10 MATCH (a:Person)-[:ACTED_IN]->(m:Movie) RETURN a, count(*) AS appearances ORDER BY appearances DESC SKIP 10
4.6 收集汇总
1
MATCH (m:Movie)<-[:ACTED_IN]-(a:Person) RETURN m.title AS movie, collect(a.name) AS cast, count(*) AS actors
4.7 使用UNION链接多个内容
1 2 3 4 5
MATCH (actor:Person)-[r:ACTED_IN]->(movie:Movie) RETURN actor.name AS name, type(r) AS type, movie.title AS title UNION MATCH (director:Person)-[r:DIRECTED]->(movie:Movie) RETURN director.name AS name, type(r) AS type, movie.title AS title
使用WITH
1
MATCH (person:Person)-[:ACTED_IN]->(m:Movie) WITH person, count(*) AS appear, collect(m.title) AS movies WHERE appear>1 RETURN person.name, appear, movies
4.8 使用约束
1 2
CREATE CONSTRAINT ON (movie:Movie) ASSERT movie.title IS UNIQUE CALL db.constraints