1

I am trying to not return the same node twice in this query in separate columns

START n=node:nodes(customer = 'c2')
MATCH n-[:OWNS]->owned-[:CROSS_SELL|UP_SELL]->sell
RETURN distinct n.customer,owned.product,sell.product

Customer C2 owns products P1 and P2. Product P2 and P3 can be cross sold from product P1. Product P3 can be also be up sold from product P2.

The query correctly returns

C2 P1 P3
C2 P2 P3
C2 P1 P2

Since the customer already owns P2, I do not want the last record in the result.

How can I accomplish this?

Thanks

4

2 回答 2

4

只需添加一个条件来过滤 C2 和 P2 之间的关系

START n=node:nodes(customer = 'c2')
MATCH n-[:OWNS]->owned-[:CROSS_SELL|UP_SELL]->sell
WHERE not(n-[:OWNS]-sell)
RETURN distinct n.customer,owned.product,sell.product
于 2013-02-14T09:10:35.807 回答
0

我还没有测试以验证这是否有效,但它似乎在逻辑上是正确的:

START n=node:nodes(customer = 'c2')
MATCH n-[:OWNS]->owned-[:CROSS_SELL|UP_SELL]->sell,
      alreadyOwns = n-[:OWNS]->sell
WHERE COUNT(alreadyOwns) = 0
RETURN distinct n.customer,owned.product,sell.product

这个想法基本上是尝试找到从起始节点到交叉/追加销售项目的直接匹配项,如果找到路径,则不要包含它。

于 2013-02-13T23:45:54.557 回答