Home > Software engineering >  Sum of counts Neo4j
Sum of counts Neo4j

Time:05-25

i want to make a count of count's, or a sum of Count's, and i'm having a problem. So i need to add 3 different fields that connect with one field named 'Pais'. And i want to add the Count's of each one to have in the final the sum of the three.

Print of the query

I saw in another stack overflow question that i can simply add two counts with a ' ' in the return statement. But I'm having a hard time trying to figure out how to solve the problem.

Thanks for the help in advance :)

CodePudding user response:

You can only do one count at a time, as it's an aggregate function. So you will want to do optional matches, take the count() each time as firstcount, secondcount etc. and add them up at the end. If you post your query in copyable format I can give more specifics.

CodePudding user response:

Try this:

MATCH (a:Atleta{genero:"Female"})-[:REPRESENTA_O]->(p:Pais) WITH p, count(a) AS atletaCount
MATCH (t:Tecnico{genero:"Female"})-[:PERTENCE]->(p) WITH p, atletaCount, count(t) AS tecnicoCount
MATCH (tr:Treinador{genero:"Female"})-[:REPRESENTA]->(p) WITH p, atletaCount, tecnicoCount, count(tr) AS treinadorCount
WITH p, atletaCount   tecnicoCount   treinadorCount AS totalCount
RETURN totalCount, p AS pais
ORDER BY totalCount DESC
  • Related