使用UNWIND时数据丢失

时间:2017-08-16 07:40:12

标签: database neo4j cypher neo4j-ogm

MATCH (ORG:ORG)-[ORGHASPROBLEM:HAS]->(PROBLEM:PROBLEM) WITH PROBLEM,

extract(NUM IN filter( V IN collect({ PROB1:PROBLEM.PROB_ID, PROB2:PROBLEM.REGION}) where V.PROB2= 'LONDON') | NUM.PROB1) AS MEASURES1,

extract(NUM IN filter( V IN collect({ PROB1:PROBLEM.PROB_ID, PROB2:PROBLEM.REGION}) where V.PROB2= 'PARIS') | NUM.PROB1) AS MEASURES2

unwind MEASURES1 AS RESULT1
unwind MEASURES2 AS RESULT2

RETURN DISTINCT PROBLEM.SLAB AS DIMENSION,count(RESULT1) AS  MEASURES1,count(RESULT2) AS MEASURES2

我正在上传数据库的图像和预期的输出。任何人都可以重写查询或告诉我哪里出错了吗?

我的问题是MEASURES1和MEASURES2有我需要的数据。当我使用展开MEASURES1 AS RESULT1时,它会根据需要提供输出,但如果是第二次展开(展开MEASURES2 AS RESULT2),则会从MEASURES1MEASURES2中删除整个数据

请参阅附图,更清楚地了解情景。

Data model, expected output

1 个答案:

答案 0 :(得分:0)

以下查询将以允许您构建报告的方式从数据库中获取数据。作为奖励,如果您添加新区域,它也会起作用:

MATCH (p:PROBLEM)
WITH count(*) AS ct, p.REGION AS pregion, p.SLAB AS slab
RETURN slab, collect({region: pregion,  count: ct}) as result;

希望这有帮助。

此致 汤姆