with 子句做什么?新4j

2024-05-20

I don't understand what WITH clause do in Neo4j. I read the The Neo4j Manual v2.2.2 http://neo4j.com/docs/stable/query-with.html#with-filter-on-aggregate-function-results but it is not quite clear about WITH clause. There are not many examples. For example I have the following graph where the blue nodes are football teams and the yellow ones are their stadiums. enter image description here

我想找到有两支或更多球队比赛的体育场。我找到了该查询并且它有效。

match (n:Team) -[r1:PLAYS]->(a:Stadium)
with a, count(*) as foaf
where foaf > 1
return a

count(*) 告诉我们匹配行的数量。但我不明白WITH子句的作用。


WITH允许您将数据从查询的一个部分传递到下一个部分。您在WITH中列出的任何内容都将在下一个查询部分中可用。

您可以将聚合、SKIP、LIMIT、ORDER BY 与WITH 一起使用,就像在RETURN 中一样。 唯一的区别是你的表达式必须获得一个别名AS alias以便能够在以后的查询部分中访问它们。

这意味着您可以链接查询部分,其中一个查询部分计算一些数据,而下一个查询部分可以使用该计算数据。在你的情况下,它是什么GROUP BY and HAVING会在 SQL 中,但WITH比这更强大。

这是另一个例子

match (n:Team) -[r1:PLAYS]->(a:Stadium)
with distinct a 
order by a.name limit 10
match (a)-[:IN_CITY]->(c:City)
return c.name
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

with 子句做什么?新4j 的相关文章

随机推荐