with子句做什么?Neo4j [英] What with clause do? Neo4j

查看:57
本文介绍了with子句做什么?Neo4j的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白 Neo4j 中 WITH 子句的作用.我阅读了 Neo4j 手册 v2.2.2 但对 WITH 子句还不是很清楚.例子并不多.例如,我有下图,其中蓝色节点是足球队,黄色节点是他们的体育场.

I don't understand what WITH clause do in Neo4j. I read the The Neo4j Manual v2.2.2 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.

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

I want to find stadiums where two or more teams play. I found that query and it works.

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

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

count(*) says us the numbers of matching rows. But I don't understand what WITH clause do.

推荐答案

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

WITH allows you to pass on data from one part of the query to the next. Whatever you list in WITH will be available in the next query part.

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

You can use aggregation, SKIP, LIMIT, ORDER BY with WITH much like in RETURN. The only difference is that your expressions have to get an alias with AS alias to be able to access them in later query parts.

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

That means you can chain query parts where one computes some data and the next query part can use that computed data. In your case it is what GROUP BY and HAVING would be in SQL but WITH is much more powerful than that.

这是另一个例子

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

这篇关于with子句做什么?Neo4j的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆