查询一组节点之间是否存在某个关系
发布于 3 个月前 作者 xtliu 428 次浏览 来自 问答

match (a:test{name:“1”}), (b:test{name:“2”}), (c:test{name:“3”}), (d:test{name:“4”}), (e:test{name:“5”}), (f:test{name:“6”}), (g:test{name:“7”}) where (not exists((a)-[]-(b))) AND (not exists((a)-[]-©)) AND (not exists((a)-[]-(d))) AND (not exists((a)-[]-(e))) AND (not exists((a)-[]-(f))) AND (not exists((a)-[]-(g))) AND (not exists((b)-[]-©)) AND (not exists((b)-[]-(d))) AND (not exists((b)-[]-(e))) AND (not exists((b)-[]-(f))) AND (not exists((b)-[]-(g))) … 各位大牛,有没什么办法可以比较优雅的完成查询呢?上面这种方法计算效率实在是太低了

2 回复

可以试试最短路径函数!

可以参考一下 同一人的亲属与父母之间关系不是亲属 match(n:idcard) where n.idcard='xxxxxxxxxxxxxxxxxx’ with n,apoc.coll.toSet([(n)-[:relatives_rel]-(m:idcard)|m]) as relatives ,apoc.coll.toSet([(n)-[:parent_rel]-(m:idcard)|m]) as parents unwind relatives as cha unwind parents as chb with n,[(cha)-[r]-(chb)|type® ] as list where list<>[‘relatives_rel’] and list<>[] with n,case when count(list)>0 then 1 else 0 end as cur_relation_btw_relativeparent return ‘cur_relation_btw_relativeparent’ as type, cur_relation_btw_relativeparent as flag

回到顶部