Question

I am trying to get an aggregate value of the number of males and females between age ranges. For example: the number of males and females under the age of 25.

MATCH (m:user)-[:gender]->(male:gender {type:"male"})
With m AS m25
where  tofloat(m25.birthday) < (timestamp()-788923800000) 
RETURN count(m25)

I want to do this all within one query so i get male and female counts for 13-25, 26-25 and so. I'm scratching my head with the collection functions because they seem to answer my question but i'm not sure how to apply them in the above context.

Any help would be appreciated!

Was it helpful?

Solution

You could either use a series of queries joined by UNIONs or chain the queries with a series of WITH clauses.

E.g.

MATCH (m25:user)-[:gender]->(male:gender {type:"male"})
where  tofloat(m25.birthday) < (timestamp()-788923800000)    
RETURN count(m25)
UNION
MATCH (f25:user)-[:gender]->(female:gender {type:"female"})
where  tofloat(f25.birthday) < (timestamp()-788923800000) 
RETURN count(f25)
UNION
...

...or...

MATCH (m25:user)-[:gender]->(male:gender {type:"male"})
where  tofloat(m25.birthday) < (timestamp()-788923800000) 
WITH count(m25) AS male25
MATCH (f25:user)-[:gender]->(male:gender {type:"female"})
where  tofloat(f25.birthday) < (timestamp()-788923800000) 
WITH count(f25) AS female25, male25
...

Etc.

HTH

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top