Neo4j - Counting Nodes with Labels

2020-07-07 10:46发布

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.

标签: neo4j
2条回答
疯言疯语
2楼-- · 2020-07-07 11:29

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
查看更多
何必那么认真
3楼-- · 2020-07-07 11:34

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.

查看更多
登录 后发表回答