cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

To get output as an array

I have written a query, which returns four columns and four columns have values in the separate rows.

But I want is that the query should return me an array for different columns, not values in the separate rows.

The query is:

MATCH(c:Company{companyId:4})<-[re:WORKS_IN]-(p:Person)-[r:HAS_SCORE]->(ps:PerformanceScores) WITH distinct ps.scoreDate as scoredate MATCH (ps:PerformanceScores {scoreDate:scoredate}) WITH ps.score as score, scoredate UNWIND scoredate as x WITH x,score,scoredate RETURN avg(score)as average,x as fulldate,["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][scoredate.month-1] as months,scoredate.year as year order by x

So what should be change in the query so that it return the values in the array.

Thanks

2 REPLIES 2

Your query is a bit difficult to read, and you haven't specified which ones you want as arrays, and which ones you want to be the "groupers". So here's a generic solution you can adapt.

Say we have this query:

MATCH (p:Person)-[:SCORE]->(s:Score)
RETURN p.name, s.value

And let's say that it returns:
David,2
David,3
Bob,1

You could instead write:

MATCH (p:Person)-[:SCORE]->(s:Score)
RETURN distinct(p.name), collect(s.value) as scores

Which would give you:
David,[2, 3]
Bob,[1]

The trick is distinct + collect. Collect creates arrays, and distinct tells you how to group them.

Thanks
I have solved the issue by using the collect function only.