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
I am uploading the image of the database and expected output. Can anybody rewrite the query or tell me where I am going wrong?
My question is that MEASURES1 and MEASURES2 have my required data. When I am using the unwind MEASURES1 AS RESULT1
it give the output as required, but in case of the 2nd unwind (unwind MEASURES2 AS RESULT2
) it removes the entire data from MEASURES1
and MEASURES2
.
Please, see the attached image to understand the scenario more clearly.
The follow query will get the data out of the database in a way that will allow you to build your report. As a bonus it will also work if you add a new region :
MATCH (p:PROBLEM)
WITH count(*) AS ct, p.REGION AS pregion, p.SLAB AS slab
RETURN slab, collect({region: pregion, count: ct}) as result;
Hope this helps.
Regards, Tom