cancel
Showing results for 
Search instead for 
Did you mean: 

Cypher to group data

bayelaye
Node

Capture d’écran du 2023-01-24 15-45-35.png

Hello Everyone,

I really need your help with a cypher code. I am working on a project and I a have the schema below.

I want for every element in the "Network_Name" column and for each  Datetime (distinct selection according to the Network_Name and Datetime) to count the number of user and return those three columns ("Network_Name", "Datetime" and user count).

Any help please

I hope I was clear enough

Thank in advance

 

1 ACCEPTED SOLUTION

glilienfield
Ninja
Ninja

Assuming a data model as follows:

Screen Shot 2023-01-24 at 12.07.23 PM.png

Then, the following query should work:

match(n:Network)<-[:BELONGS_TO]-(u:User)
return n.network_name as network_name, n.datetime as datetime, count(u) as user_count

 The key point is in the 'with' statement, where the statement groups the rows by 'network_name' and 'datatime' of the network node, then counts the number of users for each distinct group. This is how the aggregation functions works, i.e., the rows are grouped by the distinct values of the variables provided on the 'with' or 'return' statement, whenever an aggregate functions exists. 

View solution in original post

3 REPLIES 3

glilienfield
Ninja
Ninja

You forgot to provide the schema/data model.

glilienfield
Ninja
Ninja

Assuming a data model as follows:

Screen Shot 2023-01-24 at 12.07.23 PM.png

Then, the following query should work:

match(n:Network)<-[:BELONGS_TO]-(u:User)
return n.network_name as network_name, n.datetime as datetime, count(u) as user_count

 The key point is in the 'with' statement, where the statement groups the rows by 'network_name' and 'datatime' of the network node, then counts the number of users for each distinct group. This is how the aggregation functions works, i.e., the rows are grouped by the distinct values of the variables provided on the 'with' or 'return' statement, whenever an aggregate functions exists. 

bayelaye
Node

Hello 

Sorry I forget the schema but you guess it right.

That work perfectly.

Thank you very much