Database Reference
In-Depth Information
Note
There is simply not enough space in this topic to cover all the Neo4j functions in detail.
Formoreinformation,pleasereadthecomprehensiveNeo4jManual( http://docs.neo4j.org/
chunked/stable/query-function.html ) .
6.4.3. Piping using the with clause
In Cypher you can chain the output of one query to another, creating powerful graph con-
structs. The chaining (or piping) clause in Cypher is with .
To illustrate its use, let's build on a previous example where you used Cypher to count
the number of relationships of each type from the john node. Let's add a requirement to
include only relationships that occur more than once: if John has seen two movies, that
HAS_SEEN relationshipwouldbeincluded,butifhehasseenjustonemovie(ornomovies
at all), the relationship wouldn't be included.
The problem involves filtering on an aggregated function. In SQL, filtering on aggregate
functions is done using the HAVING clause, but Cypher doesn't support that. Instead, in
Cypher you can use with , as the following snippet illustrates:
The query starts with the index lookup of the starting node, then matches all relationships
connected to it. But, instead of returning the aggregated result as before, you chain it using
the with clause . In the with clause, you rename the output that will be used as input
in the chained command ( type and count ). After chaining, the output defined using the
with clause acts as input to the new where clause
. Finally, you return the matching
result
.
Search WWH ::




Custom Search