我写了一个查询,它返回四列,四列在单独的行中有值。
但我想要的是查询应该向我返回不同列的数组,而不是单独行中的值。
查询为:
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
那么查询中应该更改什么,以便它返回数组中的值。
谢谢
通常,当您希望数组中的每个结果列时,此方法有效:
MATCH (p:Person)
RETURN COLLECT(id(p)) AS ids,
COLLECT(p.name) AS names
对于您的查询,这看起来像
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
WITH { average:avg(score),
fulldate: x,
months:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][scoredate.month-1],
year:scoredate.year
} as row order by row.fulldate
RETURN COLLECT (average) as averages,
... etc