What to do with the offer? Neo4j

I don't understand what the WITH clause is in Neo4j. I have read " Neo4j Manual v2.2.2 , but it is not clear about WITH clauses. Examples are few. For example, I have the following graph where the blue nodes are football teams and the yellow nodes are their stadiums." enter image description here

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

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

      

count (*) tells us the number of matching lines. But I don't understand what the WITH clause is.

+3


source to share


1 answer


WITH

allows you to pass data from one part of the request to the next. Anything you list with WITH will be available in the next part of the query.

You can use aggregation, SKIP, LIMIT, ORDER BY with the same as in RETURN. The only difference is that your expressions must be aliased with AS alias

in order to be able to access them in later parts of the query.

This means you can link the details of the query where some data is calculated and the next part of the query can use that calculated data. In your case, that's what GROUP BY and HAVING

SQL would be, but WITH is much more powerful than that.



here is another example

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

      

+7


source







All Articles