I'm new to Cypher and I've been struggling with this particular query.
I have Person and Workshop nodes. A person is from a country.
I need a query that groups people based on their country, counts how many people is from each country and counts the relationships between countries.
Let's say Workshop A is related to Person 1 (from US) and Person 2 (from Canada). Also, Workshop B is related to Person 3 (from Brazil), Person 4 (from US) and Person 1.
Then, the expected result would be:
US node with 2 as the count property value
Canada node with 1 as the count property value
Brazil node with 1 as the count property value
Relationship between US and Brazil with 2 as the count property value (Person 1, Person 4, and Person 3 are related to Workshop B)
Relationship between US and Canada with 1 as the count property value (Person 1, Person 2 are related to Workshop A)
Relationship between US and US (self-relationship) with 1 as the count property value (Person 1, and Person 4 are related to Workshop B)
How can I get that data? I've tried just grouping but I couldn't find a way of getting the count of people grouped in each node.
given this schema that i understood from your question
(Workshop)-[RELATED]->(Person)-[FROM]->(Country)
this query seems to return what you're asking for
match (c1:Country)-[:FROM]-(p1:Person)-[:RELATED]-(w:Workshop)-[:RELATED]-(p2:Person)-[:FROM]-(c2:Country)
where c1<>c2 and p1<>p2
with c1, size (collect (distinct p1)) as citizenCount, size(collect(distinct c2)) as countryRelationCount
return c1.name, citizenCount, countryRelationCount