问题
I'd like a query that counts how many nodes have each label in the dataset. For instance:
LabelA 100 LabelB 200
I can do this for each individual label with something like
MATCH (n:LabelA) return count(n);
But, I'd like to do it for every label in one command.
回答1:
Try something like this
MATCH (n)
RETURN DISTINCT count(labels(n)), labels(n);
This will return the sum of the labels in the first column and the label name in the second.
回答2:
A quick alternative here, for single labels only, APOC Procedures offers a quick means of using the counts store to get the counts:
CALL apoc.meta.stats() YIELD labels
RETURN labels
来源:https://stackoverflow.com/questions/21555529/neo4j-counting-nodes-with-labels