Neo4j - Count Function

It takes the results from MATCH clause and counts the number of rows present in that result and returns the count value. All CQL functions should use "( )" brackets.


Following is the syntax for COUNT() function.



Before proceeding with the example, create 4 nodes in Neo4j database as shown below.

CREATE (Ram:employee{name: "Ram", sal: 20000, City: "Delhi"}) 
CREATE (Rahim:employee{name: "Rahim", sal: 25000, City: "Hyderabad"}) 
CREATE (Robert:employee{name: "Robert", sal: 30000, City: "Chennai"}) 
CREATE (Raju:employee{name: "Raju", sal: 35000, City: "Nagpur"})

Following is a sample Cypher query which demonstrates the usage of the function COUNT() in Neo4j. Here we are trying to count the employees whose salary is greater than 27000.

MATCH (n:employee)  
WHERE n.sal>27000 

To execute the above query, carry out the following steps −

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.

Browser App

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.

Return Count


On executing, you will get the following result.

Count Values