本文介绍了Neo4j:基于聚合函数过滤节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个客户节点列表和每个客户放置的订单列表,表示为与这些客户节点关联的订单节点.每个订单都有与之关联的费用数字属性.
Suppose I have a list of customer nodes and a list of orders each customer has placed represented as order nodes associated to these customer nodes. Each order has a cost numeric property associated to it.
我想退回那些平均订单量大于阈值的客户.这是一些无法正常运行的代码,可以例证我想要的内容:
I want to return those customers, whose average order is greater than a threshold. Here is some non-functioning code that exemplifies what I want:
MATCH (n0:Customer)-[]-(n1:Order)
WITH n1.cost as cost
WHERE avg(cost) > 300
RETURN n0, avg(cost)
但是,这当然不是很正确.我该怎么办?
But of course this is not quite right. How should I go about it?
推荐答案
您所拥有的很接近,您只需要在WITH
语句中进行聚合,而不是在WHERE
子句中进行
What you have is close, you just need to do the aggregation in the WITH
statement, not the WHERE
clause
MATCH (n0:Customer)-[]-(n1:Order)
WITH n0, avg(n1.cost) AS cost WHERE cost > 300
RETURN n0, cost
这篇关于Neo4j:基于聚合函数过滤节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!