I wish to count the number of incoming relationships and the number of outgoing relationships for each node (this gives some insight wrt connectivity).
I can get the number of incoming (or outgoing) using a query like:
MATCH outg=(a)-->(b)
RETURN a.name, labels(a) AS Stereotype,count(rels(outg)) AS out
ORDER BY out DESC
This works.
If, however I try adding incoming relationships:
MATCH outg=(a)-->(b), incom=(c)-->(a)
RETURN a.name, labels(a) AS Stereotype,count(rels(outg)) AS out, count(rels(incom)) AS in
ORDER BY out DESC
then it doesn't produce what I'd expect. In this case both the incoming and outgoing counts are the same and much higher than either on its own (so some sort of multiplication going on).
How should it be done and what's wrong with the logic used in the second case?
I voted for Nicole's and Sam's answers.
However I think there is much more simpler :
MATCH (a)
RETURN id(a), labels(a) as stereotype,
size((a)-->()) as out, size((a)<--()) as in
You can change id(a)
with whatever property you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With