Neo4j - Counting Nodes with Labels

℡╲_俬逩灬. 提交于 2020-05-11 05:20:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!