Neo4j Cypher:如何查询链表

3

我有些困难来设计一条密码查询。

我有一个图形数据结构,以时间记录一些数据,使用

(starting_node)-[:last]->(data1)-[:previous]->(data2)-[:previous]->(data3)->...

每个数据节点都有一个日期和一些作为属性的数据,我想对这些数据进行求和。
现在,举个例子,假设我想查询上周发生了什么事情。 我最接近的查询方式是查询类似于:
start n= ... // definition of the many starting nodes here
match n-[:last]->d1, path = d1-[:previous*0..7]->dn
where dn.date > some_date_a_week_ago

很不幸,当我得到正确路径时,我也得到了所有中间路径(从两天前、三天前等等)。
由于有许多起始节点,因此有许多可能的路径长度,在我的查询中我无法要求最长路径。此外,dn.date 可能与 date_a_week_ago 不同(如果本周只有一个数据节点,上个月只有一个数据节点,则预期路径长度为1)。
请问如何在查询中过滤掉中间路径?
提前感谢!
附言: 顺便说一下,我对图形建模还很新,如果需要改变图形结构,我会感兴趣任何答案。
1个回答

3
您可以在路径中添加一个进一步的点“ dnnext”,并添加一个条件来确保“ dn”是最后一个满足条件的点。
start n= ... // definition of the many starting nodes here
match n-[:last]->d1, path = d1-[:previous*0..7]->dn-[:previous*0..1]->dnnext
where dn.date > some_date_a_week_ago and dnnext < some_date_a_week

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接