我想知道如何在Cypher中获取列表的子集?
让我们假设以下Cypher查询:
WITH ['a','b','c'] AS set1, ['b'] AS set2
RETURN set1, set2
我想得到RETURN
的{{1}}结果,该结果是set3
的子集,只包含值set1
。
因此,['a','c']
(此示例中的set2
值)的内容已被过滤掉。
任何想法如何做到这一点?
谢谢, 柯恩
答案 0 :(得分:0)
使用Cypher,您可以在列表中使用过滤器操作,确保您保留的唯一值不是第二个列表中的值:
WITH ['a','b','c'] AS set1, ['b'] AS set2
RETURN [item in set1 WHERE NOT item in set2] as set3
虽然如果你有APOC Procedures plugin,你可以使用其中一个集合函数来执行列表减法:
WITH ['a','b','c'] AS set1, ['b'] AS set2
RETURN apoc.coll.subtract(set1, set2) as set3