Neo4j – Count Function

  • Post author:
  • Post category:Neo4j
  • Post comments:2 Comments

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

Syntax

Following is the syntax for the COUNT() function.

COUNT(<value>) 

Example

Before proceeding with the example, create 4 nodes in the 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 
RETURN COUNT(n) 

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.

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.

Result

On executing, you will get the following result.

This Post Has 2 Comments

Leave a Reply