neo4j - 将输出作为数组而不是在 neo4j 中的单独行中
问题描述
我写了一个查询,它返回四列,四列在单独的行中有值。
但我想要的是查询应该为我返回一个不同列的数组,而不是单独行中的值。
查询是:
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
推荐阅读
- c++ - 在 C++ 中以编程方式使用 rsync
- python - 从 pandas DataFrame 的列中的每个列表中删除元素
- android - Flutter - SQFlite 从数据库存储和加载图像
- c++ - 打印传递给打印函数的向量
- django - 我怎样才能伪造一个多多边形字段?
- hibernate - 如何将标准限制为另一个表中的 fk?
- progressive-web-apps - 尽管有 192x192 和 512x512 图像,但 PWA 初始屏幕图像不会在 Android 上显示
- web - 网站域名后的“/home”是什么?
- r - Python 和 R 交互
- ssis - 更改 SSIS 中的系统变量长度