RamsesXVII
RamsesXVII

Reputation: 305

How to count how many nodes have input and output degree greater than 2 in Neo4j?

I'd like to know how many nodes have input and output degree greater than 2 in Neo4j using Cypher.

Upvotes: 0

Views: 251

Answers (2)

manonthemat
manonthemat

Reputation: 6251

MATCH (n)
WHERE size((n)-->()) > 2 AND size((n)<--()) > 2
RETURN count(n)

Upvotes: 3

Gabor Szarnyas
Gabor Szarnyas

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

Related Questions