I query paths within a Neo4j graph. The path contains more than two nodes. I want to count the distinct occurences of a two-node subpath.
So in the following example I want to know the number of the resulting rows:
MATCH ()-->(n1:Label1)-->(n2:Label2)-->()
RETURN DISTINCT n1, n2
E.g. something like
RETURN count(DISTINCT n1, n2)
(which would work for a single node: RETURN count(DISTINCT n1)
)
How can I do this in Cypher?
(:City)<-[:LIVES_IN]-(n1:Person)-[:KNOWS]->(n2:Person)-[:LIVES-IN]->(:City)
I am looking for a query that answers the question: How many unique (n1
,n2
)-tuples do exist that match the pattern above? – thando