Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Neo4j Cypher query do similar thing as "Having" in SQL?

Tags:

neo4j

cypher

SQL has "Having" clause, for example:

SELECT LastName, COUNT(*)
FROM Employees
GROUP BY LastName
HAVING COUNT(*) > 10; 

In Cypher, we can do count()

START n=node(2)
MATCH (n)-[r]->()
RETURN type(r), count(*)

But does Cypher have similar function as "Having", or is there any workaround?

like image 478
William Zhang Avatar asked Sep 01 '25 05:09

William Zhang


1 Answers

Sure, having is just one of the many uses of query chaining with WITH which is similar to RETURN but determines which elements will be available in the next query part. WITH also supports ordering and paging.

START n=node(2)
MATCH (n)-[r]->()
WITH type(r) as t, count(*) as c
WHERE c > 10
RETURN t,c
like image 110
Michael Hunger Avatar answered Sep 05 '25 21:09

Michael Hunger