Reputation: 305
I'd like to know how many nodes have input and output degree greater than 2 in Neo4j using Cypher.
Upvotes: 0
Views: 251
Reputation: 6251
MATCH (n)
WHERE size((n)-->()) > 2 AND size((n)<--()) > 2
RETURN count(n)
Upvotes: 3
Reputation: 5047
This should do the trick:
MATCH (n)
OPTIONAL MATCH (n)-[out]->()
OPTIONAL MATCH (n)<-[in]-()
WITH n, COUNT(out) AS outDegree, COUNT(in) AS inDegree
WHERE outDegree > 2
AND inDegree > 2
RETURN COUNT(n)
Upvotes: 1