Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What with clause do? Neo4j

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. enter image description here

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(*) says us the numbers of matching rows. But I don't understand what WITH clause do.

like image 690
DistribuzioneGaussiana Avatar asked Jun 07 '15 22:06

DistribuzioneGaussiana


People also ask

Which clause is used to search the data with a specified pattern in Neo4j?

The MATCH clause allows you to specify the patterns Neo4j will search for in the database.

How can I improve my Neo4j performance?

Heap Sizing The size of the available heap memory is an important aspect for the performance of Neo4j. Generally speaking, it is beneficial to configure a large enough heap space to sustain concurrent operations. For many setups, a heap size between 8G and 16G is large enough to run Neo4j reliably.

What are the weaknesses of Neo4j?

Additionally, Neo4j has scalability weaknesses related to scaling writes, hence if your application is expected to have very large write throughputs, then Neo4j is not for you.

How do you perform an aggregation in Cypher?

The Cypher query offers aggregation similar to GROUP BY offered by SQL. The aggregate function can take multiple values and can calculate the aggregated values for them. In this recipe, we will learn the common aggregation techniques, with the help of examples.


1 Answers

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.

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.

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.

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
like image 186
Michael Hunger Avatar answered Sep 28 '22 17:09

Michael Hunger