“Invalid use of aggregating function in this context” in a SET query (Neo4j)

时光毁灭记忆、已成空白 提交于 2019-12-24 01:19:25

问题


I wonder why this is considered an invalid use of aggregate functions in Neo4j's Cypher:

MATCH (p:Project)-[:EMPLOYS]-(n:Person) SET p.youngest = MIN(n.age);

While the following is considered a valid use case:

MATCH (p:Project)-[:EMPLOYS]-(n:Person) RETURN p.name, MIN(n.age) AS youngest;

How should I rewrite the first query to make it valid?


回答1:


As for "why" your original Cypher attempt does not work, and the answer by @mah does work: Cypher only permits aggregation functions to be used in WITH and RETURN clauses.




回答2:


A slight change to the query makes it work:

MATCH (p:Project)-[:EMPLOYS]-(n:Person)
WITH p, MIN(n.age) AS min_age 
SET p.youngest = min_age;


来源:https://stackoverflow.com/questions/27491698/invalid-use-of-aggregating-function-in-this-context-in-a-set-query-neo4j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!