Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-15-2022 08:13 AM
Hello everybody, I would like to create nested count structures and check if a certain condition(s) is (are) satisfied. To illustrated what I would like to achieve I have created a simple cypher-example as you see in the following query. However, this query is not working since after a CALL a WHERE cannot be placed. I also tried different constellations also inside the WHERE with EXISTS which is also not working.
MATCH (p:Regesta)
CALL { MATCH (p)-->(other) RETURN count(other) as myCount }
WHERE myCount > 3
RETURN p LIMIT 10
Solved! Go to Solution.
12-02-2022 03:56 AM
Hello @glilienfield,
thanks for your reply, but that is not what I wanted. I wanted to be flexible in the way I do the nesting with count. Since CALL {}-subquery can not be placed inside of a CALL {}-subquery, I assumed it should work with EXISTS{}-SUBQUERY. However, in EXISTS{}-SUBQUERY, no WITH-Clause can be called to define what shall be counted. CALL-IN-A-CALL still does not work see it at:
https://neo4j.com/docs/cypher-manual/5/clauses/call-subquery/
https://neo4j.com/docs/cypher-manual/4.4/clauses/call-subquery/
That is just regarding Cypher 4.4. I also asked my question in the discord developer chat, and just a few weeks later, they created Cypher 5.X functionality for subquery with Count. See: https://neo4j.com/docs/cypher-cheat-sheet/5/
From now on Cypher has the Subcall-procedure for COUNT.
MATCH (p:Regesta)
WHERE COUNT { (p)--(d:other) } > 1
RETURN p.name AS name
In this example the path will be counted and inside of the COUNT{} x further COUNTS{} can be placed.
09-15-2022 01:08 PM
Try this, as you don't need a subquery:
MATCH (p:Regesta)-->(other)
WITH p, count(other) as myCount
WHERE myCount > 1
RETURN p, myCount
LIMIT 10
I refactored your query to get it to work:
MATCH (p:Regesta)
CALL {
WITH p
MATCH (p)-->(other)
RETURN count(other) as myCount
}
WITH p, myCount
WHERE myCount > 3
RETURN p, myCount
LIMIT 10
12-02-2022 03:56 AM
Hello @glilienfield,
thanks for your reply, but that is not what I wanted. I wanted to be flexible in the way I do the nesting with count. Since CALL {}-subquery can not be placed inside of a CALL {}-subquery, I assumed it should work with EXISTS{}-SUBQUERY. However, in EXISTS{}-SUBQUERY, no WITH-Clause can be called to define what shall be counted. CALL-IN-A-CALL still does not work see it at:
https://neo4j.com/docs/cypher-manual/5/clauses/call-subquery/
https://neo4j.com/docs/cypher-manual/4.4/clauses/call-subquery/
That is just regarding Cypher 4.4. I also asked my question in the discord developer chat, and just a few weeks later, they created Cypher 5.X functionality for subquery with Count. See: https://neo4j.com/docs/cypher-cheat-sheet/5/
From now on Cypher has the Subcall-procedure for COUNT.
MATCH (p:Regesta)
WHERE COUNT { (p)--(d:other) } > 1
RETURN p.name AS name
In this example the path will be counted and inside of the COUNT{} x further COUNTS{} can be placed.
All the sessions of the conference are now available online