[英]Neo4j Cypher Query to get all sub nodes until reaching a node with a specific relationship
I am trying create a query in which starts with the blue nodes called "Analytical Units".我正在尝试创建一个查询,其中以名为“分析单位”的蓝色节点开头。 The query will get all sub-nodes unless it runs into a node which "overrides" the relationship by being directly attached to a different analytical unit.
查询将获取所有子节点,除非它遇到一个节点,该节点通过直接附加到不同的分析单元来“覆盖”关系。 Any help would be appreciated!
任何帮助,将不胜感激!
Does this query work for you?这个查询对你有用吗?
It should return each Blue
node (that has a path to any Red
nodes) and its "sub-nodes" (along each of those paths), ignoring paths in which any sub-node (except the first) has an incoming ANALYTICALLY_COMPOSED
relationship:它应该返回每个
Blue
节点(具有到任何Red
节点的路径)及其“子节点”(沿着每条路径),忽略任何子节点(第一个除外)具有传入ANALYTICALLY_COMPOSED
关系的路径:
MATCH (a:Blue)-[:ANALYTICALLY_COMPOSED]->(b)
MATCH p=(b)-[rels*]-(:Red)
WITH a, NODES(p) AS subnodes
WHERE NONE(n IN subnodes[1..] WHERE ()-[:ANALYTICALLY_COMPOSED]->(n))
RETURN a, subnodes;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.