如何在neo4j中保存变量avg_time?以在另一个查询中返回它。
WITH '
MATCH (a:authors{name:"Lui Lis"})-[:`WROTE`]->(b:papers)-[:`REFERS_TO`]->(c:fieldsofstudy)
RETURN c.name AS field_of_study, count(b) AS number_of_papers
' AS query
UNWIND RANGE(0, 4) AS i
WITH i, query, datetime.realtime().epochMillis AS start
CALL apoc.cypher.doIt(query, NULL) YIELD value
WITH i, MAX(datetime.realtime().epochMillis-start) AS execTime
WITH COLLECT({x: execTime, y: i}) AS per_query_times, AVG(execTime) AS avg_time
UNWIND per_query_times AS z
RETURN z.x AS x, z.y AS y, avg_time
因为在这段代码中,它返回avg_time 5次,而我只想要一次。我知道我可以只返回per_query_times和avg_time而不展开任何内容,但它不适合我
1条答案
按热度按时间nafvub8i1#
你可能应该使用子查询来代替,而且最好知道你想用查询实现什么。
您可以将数据存储在图形中的现有节点或新节点上。
或者有
apoc.static.set/get
允许您保存数据,但这些数据将在服务器重启时消失。https://neo4j.com/labs/apoc/5/overview/apoc.static/
(note这是apoc扩展的,不是apoc核心)