使用 UNWIND 时数据丢失
Data is loss when I use the UNWIND
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 有我需要的数据。当我使用 unwind MEASURES1 AS RESULT1
时,它会根据需要提供输出,但是在第二次 unwind (unwind MEASURES2 AS RESULT2
) 的情况下,它会从 MEASURES1
和 MEASURES2
中删除整个数据.
请查看附图以更清楚地了解场景。
下面的查询将以允许您构建报告的方式从数据库中获取数据。作为奖励,如果您添加一个新区域,它也将起作用:
MATCH (p:PROBLEM)
WITH count(*) AS ct, p.REGION AS pregion, p.SLAB AS slab
RETURN slab, collect({region: pregion, count: ct}) as result;
希望对您有所帮助。
此致,
汤姆
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 有我需要的数据。当我使用 unwind MEASURES1 AS RESULT1
时,它会根据需要提供输出,但是在第二次 unwind (unwind MEASURES2 AS RESULT2
) 的情况下,它会从 MEASURES1
和 MEASURES2
中删除整个数据.
请查看附图以更清楚地了解场景。
下面的查询将以允许您构建报告的方式从数据库中获取数据。作为奖励,如果您添加一个新区域,它也将起作用:
MATCH (p:PROBLEM)
WITH count(*) AS ct, p.REGION AS pregion, p.SLAB AS slab
RETURN slab, collect({region: pregion, count: ct}) as result;
希望对您有所帮助。
此致, 汤姆