Neo4J |关系列表上的密码汇总 [英] Neo4J | Cypher Aggregation on list of relationships

查看:88
本文介绍了Neo4J |关系列表上的密码汇总的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Neo4J/Cypher的新功能,这是我的查询:

New to Neo4J/Cypher and here is my query:

MATCH (origin:BusStop)-[bus*]->(destination:BusStop)
WITH bus
WHERE origin.name =~ '(?i).*Origin.*' 
AND destination.name =~ '(?i).*Destination.*' 
AND all(rel in bus where rel.day in ['Sat'])
RETURN bus

我正在尝试获取始发地和目的地之间的所有可能的巴士.我还希望上述查询中的总票价(作为总和功能).

I'm trying to get all the possible buses between the Origin and Destination. I also want the total fare (as a sum function) in the above query.

注意:该关系具有一个称为fare SUM(bus.fare))的属性.

Note: The relationship has a property called fare SUM(bus.fare)).

推荐答案

使用 APOC程序,您可以对集合的元素求和,尽管您需要从公交集合中的每个关系中提取票价:

With APOC Procedures you can sum elements of a collection, though you'll need to extract the fare value from each relationship in the bus collection:

RETURN bus, apoc.coll.sum([rel in bus | rel.fare]) as totalFare

没有APOC程序,您将需要使用REDUCE():

Without APOC Procedures, you'll need to use REDUCE():

RETURN bus, reduce(total = 0, rel in bus | total + rel.fare) as totalFare

这篇关于Neo4J |关系列表上的密码汇总的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆