I'm now making an application uses neo4j as my database. I have one class:
class Person
{
public string Id{get;set;}
public int Role{get;set;}
public int Status {get;set;}
}
Now I have 50 nodes, 25 of them are :
{
Id : <GUID>
Role: 3,
Status : 0
}
And the other 25 are :
{
Id: <GUID>
Role: 3,
Status : 2
}
I want to statistic the people base on their role and status. With those records above, I have:
25 people have role 3 and status is 0
25 people have role 3 and status is 2
I've tried this query :
MATCH (a:Person), (b:Person)
WHERE (a.Status = 0 AND a.Role = 3) OR (b.Status = 2 AND b.Role = 3)
RETURN COUNT(a), COUNT(b)
Instead of 25, 25.
It gave me : 6976, 6976
I don't know what the problem is.
Can anyone help me please ? Thank you.
P/S: I'm using graphenedb.
Your statement builds a cross product of all person in your graph.
Try this instead
MATCH (p:Person)
RETURN p.Role, p.Status, count(*)
In Cypher there's no "group by". If you use an aggregation function like count
aggregation is done automatically on the other expressions (here p.Role
and p.Status
).