I am doing a PoC to find out if a graph database will fit our needs.
We have a survey in which respondents have answered questions. We want to group these respondents using every possible combination of answers out of a set of (mostly two or three) questions.
I have the following nodes and relationships
(:Question)-[:HasAnswer]->(:Answer)
(:Respondent)-[:Answered]->(:Answer)
(:Answer)-[:BelongsTo]->(:WeightingGroup)
In which:
- Question: the question
- Answer: A possible answer to a question
- Respondent: A person that answered questions
- Answered: The relation between a respondent that answered a question
- WeightingGroup: A group of answers that form unique combinations of given answers
- BelongsTo: The relationship between an answer and a weightinggroup to form groups of answers.
My goal is to receive a result like this:
/----------------------------------------------\
| Q1 | Q2 | n |
|--------------------+-------------------------|
| Answer1 | Answer1 | 23 |
| Answer1 | Answer2 | 12 |
| Answer1 | Answer3 | 54 |
| Answer2 | Answer1 | 65 |
| Answer2 | Answer1 | 5 |
| Answer2 | Answer1 | 15 |
\--------------------+--------------------+----/
or:
/-------------------------\
| Q1, Q2 | n |
|--------------------+----|
| Answer1, Answer2 | 23 |
| Answer1, Answer2 | 12 |
| Answer1, Answer3 | 54 |
| Answer2, Answer1 | 65 |
| Answer2, Answer1 | 5 |
| Answer2, Answer1 | 15 |
\--------------------+----/
Where n is the number of respondents that gave both answers.
However, when I run this query:
// Aantal antwoorden per wegingsgroep
match (w:WeightingGroup)-[]->(a:Answer)<-[:Answered]-(r:Respondent)
with w, collect(distinct a.Text) as answers, count(distinct r) as n
return answers, w.Weight, n
It seems to be returning n = the number of respondents that answered answer1 OR answer2.
How do get the count of Respondents that gave answer1 AND answer2?
Thanks in advance!