Neo4j 简明教程
Neo4j - Count Function
假设我们在数据库中创建了具有以下详细信息的图表。
Assume we have created a graph in the database with the following details.

Count
count() 函数用于统计行数。
The count() function is used to count the number of rows.
Syntax
如下是计数函数的语法。
Following is the syntax of the count function.
MATCH (n { name: 'A' })-->(x)
RETURN n, count(*)
Example
以下是演示 count() 函数用法的一个 Cypher 查询示例。
Following is a sample Cypher Query which demonstrates the usage of the count() function.
Match(n{name: "India", result: "Winners"})--(x)
RETURN n, count(*)
执行上述查询,执行以下步骤:
To execute the above query, carry out the following steps −
Step 1 - 打开 Neo4j Desktop App 并启动 Neo4j Server。使用 URL http://localhost:7474/ 打开 Neo4j 的内置浏览器应用,如下面的屏幕截图所示。
Step 1 − Open the Neo4j desktop App and start the Neo4j Server. Open the built-in browser app of Neo4j using the URL http://localhost:7474/ as shown in the following screenshot.

Step 2 - 在美元提示符中复制并粘贴所需的查询,并按播放按钮(执行查询)突出显示在下面的屏幕截图中。
Step 2 − Copy and paste the desired query in the dollar prompt and press the play button (to execute the query) highlighted in the following screenshot.

Group Count
COUNT 子句还用于统计关系类型组。
The COUNT clause is also used to count the groups of relationship types.
Example
以下是统计参与每个关系的节点的数量并返回的 Cypher 查询示例。
Following is a sample Cypher Query which counts and returns the number of nodes participating in each relation.
Match(n{name: "India", result: "Winners"})-[r]-(x)
RETURN type (r), count(*)
执行上述查询,执行以下步骤:
To execute the above query, carry out the following steps −
Step 1 - 打开 Neo4j Desktop App 并启动 Neo4j Server。使用 URL http://localhost:7474/ 打开 Neo4j 的内置浏览器应用,如下面的屏幕截图所示。
Step 1 − Open the Neo4j desktop App and start the Neo4j Server. Open the built-in browser app of Neo4j using the URL http://localhost:7474/ as shown in the following screenshot.

Step 2 - 在美元提示符中复制并粘贴所需的查询,并按播放按钮(执行查询)突出显示在下面的屏幕截图中。
Step 2 − Copy and paste the desired query in the dollar prompt and press the play button (to execute the query) highlighted in the following screenshot.
