4

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?

William Zhang
  • 125
  • 3
  • 9

1 Answers1

14

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
Michael Hunger
  • 41,339
  • 3
  • 57
  • 80