我有以下节点:
指导
操作
客户
我有以下关系
引导-[执行]->操作
操作 -[OPERATION_FOR]-> 客户
在
OPERATION_FOR
关系上,我有一个属性 guid
,它与 id
节点的 Guid
属性具有相同的值。
当我执行以下查询时
MATCH (guid:Guid{id:"005056AF0E7F1EECB0E4FCC33F085227"}) -[perform:PERFORMS]->(operation:Operation)
MATCH (operation) -[operationFor:OPERATION_FOR{guid:guid.id}]-> (customer:Customer)
RETURN operationFor,operation,customer
我预计有 5 个结果。 Graph 界面确实显示了 5 个关系,但实际上有 11 个关系
当我查看文本视图时,它显示 11 个条目,但有重复项。我发现了与此相关的其他问题,但这些问题的查询没有指定关系的方向,因此它被计算了两次。但我确实指定了方向,所以我不确定为什么会这样。
操作对于 | 操作 | 顾客 |
---|---|---|
[:OPERATION_FOR {guid: "005056AF0E7F1EECB0E4FCC33F085227",startTime: "2022-04-23T18:50:30",endTime: "2022-04-23T19:10:36"}] | (:操作 {id: "SHIP"}) | (:客户{id: "BP0103"}) |
[:OPERATION_FOR {guid: "005056AF0E7F1EECB0E4FCC33F085227",startTime: "2022-04-23T18:50:30",endTime: "2022-04-23T19:10:36"}] | (:操作 {id: "SHIP"}) | (:客户{id: "BP0103"}) |
[:OPERATION_FOR {guid: "005056AF0E7F1EECB0E4FCC33F085227",startTime: "2022-04-23T17:50:30",endTime: "2022-04-23T17:50:36"}] | (:操作 {id: "SHIP"}) | (:客户{id: "BP0103"}) |
[:OPERATION_FOR {guid: "005056AF0E7F1EECB0E4FCC33F085227",startTime: "2022-04-23T18:50:30",endTime: "2022-04-23T19:10:36"}] | (:操作 {id: "STORE"}) | (:客户 {id: "Flexo"}) |
[:OPERATION_FOR {guid: "005056AF0E7F1EECB0E4FCC33F085227",startTime: "2022-04-23T18:50:30",endTime: "2022-04-23T19:10:36"}] | (:操作 {id: "LOAD"}) | (:客户 {id: "Elision"}) |
[:OPERATION_FOR {guid: "005056AF0E7F1EECB0E4FCC33F085227",startTime: "2022-04-23T18:50:30",endTime: "2022-04-23T19:10:36"}] | (:操作 {id: "SHIP"}) | (:客户{id: "BP0103"}) |
[:OPERATION_FOR {guid: "005056AF0E7F1EECB0E4FCC33F085227",startTime: "2022-04-23T18:50:30",endTime: "2022-04-23T19:10:36"}] | (:操作 {id: "SHIP"}) | (:客户{id: "BP0103"}) |
[:OPERATION_FOR {guid: "005056AF0E7F1EECB0E4FCC33F085227",startTime: "2022-04-23T17:50:30",endTime: "2022-04-23T17:50:36"}] | (:操作 {id: "SHIP"}) | (:客户{id: "BP0103"}) |
[:OPERATION_FOR {guid: "005056AF0E7F1EECB0E4FCC33F085227",startTime: "2022-04-23T18:50:30",endTime: "2022-04-23T19:10:36"}] | (:操作 {id: "SHIP"}) | (:客户{id: "BP0103"}) |
[:OPERATION_FOR {guid: "005056AF0E7F1EECB0E4FCC33F085227",startTime: "2022-04-23T18:50:30",endTime: "2022-04-23T19:10:36"}] | (:操作 {id: "SHIP"}) | (:客户{id: "BP0103"}) |
[:OPERATION_FOR {guid: "005056AF0E7F1EECB0E4FCC33F085227",startTime: "2022-04-23T17:50:30",endTime: "2022-04-23T17:50:36"}] | (:操作 {id: "SHIP"}) | (:客户{id: "BP0103"}) |
当我执行
RETURN DISTINCT(operationFor),operation,customer
或执行以下查询时
MATCH (operation:Operation) -[operationFor:OPERATION_FOR{guid:"005056AF0E7F1EECB0E4FCC33F085227"}]-> (customer:Customer)
RETURN operationFor,operation,customer
我确实在表中得到了 5 个独特的条目。
操作对于 | 操作 | 顾客 |
---|---|---|
[:OPERATION_FOR {guid: "005056AF0E7F1EECB0E4FCC33F085227",startTime: "2022-04-23T18:50:30",endTime: "2022-04-23T19:10:36"}] | (:操作 {id: "SHIP"}) | (:客户{id: "BP0103"}) |
[:OPERATION_FOR {guid: "005056AF0E7F1EECB0E4FCC33F085227",startTime: "2022-04-23T18:50:30",endTime: "2022-04-23T19:10:36"}] | (:操作 {id: "SHIP"}) | (:客户{id: "BP0103"}) |
[:OPERATION_FOR {guid: "005056AF0E7F1EECB0E4FCC33F085227",startTime: "2022-04-23T17:50:30",endTime: "2022-04-23T17:50:36"}] | (:操作 {id: "SHIP"}) | (:客户{id: "BP0103"}) |
[:OPERATION_FOR {guid: "005056AF0E7F1EECB0E4FCC33F085227",startTime: "2022-04-23T18:50:30",endTime: "2022-04-23T19:10:36"}] | (:操作 {id: "STORE"}) | (:客户 {id: "Flexo"}) |
[:OPERATION_FOR {guid: "005056AF0E7F1EECB0E4FCC33F085227",startTime: "2022-04-23T18:50:30",endTime: "2022-04-23T19:10:36"}] | (:操作 {id: "LOAD"}) | (:客户 {id: "Elision"}) |
这是因为你们连续进行了两场比赛。 第一个 MATCH 将返回 5 行(Guid 执行的每个操作对应一行)。
第二场比赛将对第一场比赛的每一行进行一次。
只执行一次的两个操作也只会从第二场比赛中得到一个结果。但是,进行了三次的操作从第一场比赛中产生了三行,并且每个人都会在第二场比赛中获得三个命中。
因此最终结果有 3*3+2 = 11 行。
正如您自己建议的那样,解决方案是使用 DISTINCT。