Neo4j - Cypher查询根据时间戳查找所有下一个节点和关系

问题描述 投票:0回答:1

我在Neo4j中有下图。在下图中,Subscriber是在不同时间执行不同操作的实体。动作是图中的关系(ComplainedRechargedEnquiredClicked)。

我的要求是编写Cypher查询以获取所有Subscriber的所有下一个动作(例如:我希望查询找到所有使用Subscriber完成Recharged动作的RechargeType=TT执行的下一个动作。我需要获取基于时间的下一个动作(ActionTime)

我还提供了链接,以便在编写以下查询后返回.xls中返回的图表的全部数据。

Graph Data

match(n)-[r]->(k)
return n, r, type(r), k

下面的查询返回RechargeType ='TT'的所有订阅者的详细信息。我需要的是cypher查询,以便根据“ActionTime”获取这些Subscriber立即采取的下一步行动,并根据所采取的行动对其进行分组(Recharged,Clicked,Complained,Inquired)。

查询:match(n:Subscriber) - [r:Recharged] - >(k)其中r.RechargeType ='TT'返回n,r,type(r),k;

enter image description here

如果我的问题有待解答,请告知我是否需要进一步的细节/解释。

编辑:图形数据已被修改,使所有操作的动作时间相同(在这种情况下为关系),并且已上载修改后的图形图像。

Graph

neo4j cypher
1个回答
0
投票

以下查询是我的问题的答案。

MATCH (n) with n, collect(n.msisdn) as list 
Match (n) WHERE n.msisdn IN list
MATCH (n)-[r]->(k) WHERE r.ActionType='TT'
WITH n, MIN(r.ActionTime) as min
MATCH (n)-[rout]->() WHERE rout.ActionTime > min
WITH n, rout
ORDER BY rout.ActionTime
WITH n, COLLECT(rout)[0] AS r
RETURN {
node: n,
outgoing:
  { relationship: TYPE(r), 
    node: ENDNODE(r),
    rType: r.ActionType,
    rTime: r.ActionTime,
    rChannel: r.ContactChannel
  }
  } AS result;
© www.soinside.com 2019 - 2024. All rights reserved.