简体   繁体   English

匹配具有相同属性的节点之间的关系

[英]Match relationships between nodes with the same property

I've the following graph:我有以下图表:

CREATE (a:Node)
CREATE (b:Node)
CREATE (c:Node)
CREATE (d:Node)

CREATE (a)-[:rel {referenceId: 1234, amount: 2}]->(b)
CREATE (b)-[:rel {referenceId: 1234, amount: 1}]->(c)
CREATE (b)-[:rel {referenceId: 1234, amount: 0.5}]->(d)

CREATE (a)-[:rel {referenceId: 4567, amount: 4}]->(b)
CREATE (b)-[:rel {referenceId: 4567, amount: 1}]->(c)
CREATE (b)-[:rel {referenceId: 4567, amount: 3}]->(d)

I'm looking for a way to calculate the difference between the amounts sent from a to b and from b to c/d depending on the referenceId but without using a specific referenceId.我正在寻找一种方法来计算从 a 发送到 b 和从 b 发送到 c/d 的金额之间的差异,具体取决于 referenceId 但不使用特定的 referenceId。

So I'm looking for something like the semi-code below:所以我正在寻找类似下面的半代码的东西:

MATCH (a)-[in:rel]->(b)-[out:rel]->(c) WHERE in.referenceId == out.referenceId RETURN SUM(in.amount)-SUM(out.amount)

Is anyone having any idea how I can do this?有人知道我该怎么做吗?

Maybe you need to do it per referenceId then?也许你需要按照referenceId来做?

  MATCH (a)-[in:rel]->(b)-[out:rel]->(c)
     WHERE in.referenceId = out.referenceId
  RETURN in.referenceId as referenceId, 
         SUM(in.amount)-SUM(out.amount) as diff

Result:结果:

referenceId diff
4567        4
1234        2.5

You can also do it in a way so you look for non zero diff:您也可以通过某种方式来查找非零差异:

MATCH (a)-[in:rel]->(b)-[out:rel]->(c)
  WHERE in.referenceId = out.referenceId
WITH in.referenceId as referenceId,
       SUM(in.amount)-SUM(out.amount) as diff
WHERE diff <> 0
RETURN referenceId, diff

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在具有相同属性的节点之间创建关系 - Creating relationships between nodes with same properties 在具有不同属性的节点之间创建相同的关系 - Create same relationships between nodes with different properties 查找所有关系具有相同属性值的两个节点之间的最短路径 - Find shortest path between two nodes with all relationships having the same property value 简化cypher,匹配所有节点和两种节点类型之间的关系 - Simplifying cypher, match all nodes and relationships between two node types 相同类型的多个关系,但在相同的两个节点之间具有不同的属性 - Multiple relationships of the same type but with different properties between the same two nodes 密码:根据公共属性键ID在节点之间创建关系 - Cypher: Create relationships between nodes based on a common property key id 是否可以在具有相同 label 的节点之间创建双向关系? - Is it possible to create bi-directional relationships between nodes with the same label? neo4j - 查找与节点关系的所有节点,这些节点匹配x长度的属性值列表 - neo4j - Find all nodes with relationships to nodes that match a list of property values of x length 匹配具有互惠关系的节点对 - Match pairs of nodes with reciprocal relationships 匹配所有节点并返回节点+关系 - Match all nodes and return nodes + relationships
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM