在获取两个值的总和并找到差异方面,我一直在与 Cypher 进行一些斗争。我有这两个查询,它们查找节点的发送总数和接收总数:
START addr = node(5)
MATCH addr <- [:owns] - owner - [to:transfers] -> receiver
RETURN SUM(to.value) AS Total_Sent
START addr = node(5)
MATCH addr <- [:owns] - owner <- [from:transfers] - sender
RETURN SUM(from.value) AS Total_Received
基本上我的问题是 - 我如何结合这两个单独的查询,以便我可以区分 Total_Sent 和 Total_Received?我尝试了多个起点,如下所示:
START sendAddr = node(5), receivedAddr = node(5)
MATCH sendAddr <- [:owns] - sendOwner - [to:transfers] -> receiver, receivedAddr <- [:owns] - receiveOwner <- [from:transfers] - sender
RETURN SUM(to.value) AS Total_Sent, SUM(from.value) AS Total_Received, SUM(to.value) - SUM(from.value) AS Balance
但 Total_Received 为空!对我来说,这看起来像是一个非常简单的用例——我到底做错了什么?