Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-09-2022 12:51 AM - edited 11-09-2022 02:05 AM
I am trying to fetch date-wise running total of member counts.
The relationships in data base are like this
(city:City) //has name property
-[:Has_Club]->
(c:Club) // has name property
-[:Has_Member]->
(p:Person{
name:"XYZ", //string
joinDate: date}) // in_datetime_format
So if the member count is as shown below I want to generate the running total
/ day mem_count on a particular date running total for memcount 1. date1 30 30 2. date2 10 40 // 10 + 30 3. date3 15 55 // 15 + 40
I wrote this query to use REDUCE function in neo4j. I only wanted the day column and running_total_column
match
(city:City{name:"city_name"})
-[:Has_Club]->
(club:Club{name:"clubName"})
-[:Has_Member]->
(p:Person)
with p.joinDate as jd, collect(count(*)) as dateColl
return distinct(date(jd)) as day, reduce(cons = 0, i in dateColl | i+ cons) as memberCount
But it gave the following error
Can't use aggregate functions inside of aggregate functions. (line 13, column 36 (offset: 401)) " with p.joinDate as jd, collect(count(*)) as dateColl"
What am I doing wrong? What do I need to change in my Query?
11-09-2022 01:29 AM
Hello @amritanshu1912 🙂
This query should do what you want:
MATCH (city:City {name: "city_name"})-[:Has_Club]->(club:Club {name: "clubName"})-[:Has_Member]->(p:Person)
RETURN date(p.joinDate) AS jd, count(DISTINCT p) AS memberCount
Regards,
Cobra
11-09-2022 01:55 AM - edited 11-09-2022 02:10 AM
i want to get the running total, this query you have suggested only produces member count of a particular day. in your suggested query, is there any way I can collect the memberCount values in a list, so that I can use that list with reduce function in the return statement
11-09-2022 05:20 AM
The result should be?
11-09-2022 12:51 PM
Can you share some Cypher queries to create a little dataset to work with please? It will be helpful to develop the query.
11-10-2022 12:56 PM
Try this:
match (club:Club)-[:Has_Member]->(p:Person)
with p.joinDate as jd, count(p) as dailyClubCount
with collect(jd) as dates, collect({date: jd, count: dailyClubCount}) as dailyStats
order by dates
unwind dates as date
return date,
reduce(s=0,i in [x in dailyStats where x.date<=date|x.count] | s + i) as `Running Count`
All the sessions of the conference are now available online