我正在做一个PoC,以确定图形数据库是否符合我们的需求。
我们进行了一项调查,受访者回答了问题。我们希望使用一组(主要是两到三个)问题中的每个可能的答案组合对这些受访者进行分组。
我有以下节点和关系
(:Question)-[:HasAnswer]->(:Answer)
(:Respondent)-[:Answered]->(:Answer)
(:Answer)-[:BelongsTo]->(:WeightingGroup)
其中:
我的目标是收到这样的结果:
/----------------------------------------------\
| Q1 | Q2 | n |
|--------------------+-------------------------|
| Answer1 | Answer1 | 23 |
| Answer1 | Answer2 | 12 |
| Answer1 | Answer3 | 54 |
| Answer2 | Answer1 | 65 |
| Answer2 | Answer1 | 5 |
| Answer2 | Answer1 | 15 |
\--------------------+--------------------+----/
或:
/-------------------------\
| Q1, Q2 | n |
|--------------------+----|
| Answer1, Answer2 | 23 |
| Answer1, Answer2 | 12 |
| Answer1, Answer3 | 54 |
| Answer2, Answer1 | 65 |
| Answer2, Answer1 | 5 |
| Answer2, Answer1 | 15 |
\--------------------+----/
其中n是给出两个答案的答复者的数量。
但是,当我运行此查询时:
// 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
似乎正在返回n =回答answer1或answer2的受访者数量。
如何获得给出answer1和answer2的受访者的数量?
提前致谢!
答案 0 :(得分:3)
这样的事情:每个小组收集答案,收集每个受访者的答案,过滤答案的所有答案出现在一个小组的答案中。我认为对受访者的指望应该没问题(因为答案已经收集,所以你必须提取答案文本。)
MATCH (g:WeightingGroup)<-[:BelongsTo]-(a)
WITH g, collect(a) as apg
MATCH (r:Respondent)-[:Answered]->(a)
WITH g, apg, r, collect(a) as apr
WHERE ALL(a IN apr WHERE a IN apg)
RETURN g.Weight, EXTRACT(a IN apg | a.Text), count(r) as n