简体   繁体   English

如何返回两个不同的列表?

[英]How can I return two lists that are DISTINCT?

How can I return two lists that are DISTINCT ?如何返回两个不同的DISTINCT I use UNWIND clause to do that with one, but the problem arises when I want to have two independent lists with DISTINCT elements.我使用UNWIND子句对其中一个执行此操作,但是当我想拥有两个包含DISTINCT元素的独立列表时,问题就出现了。

Here is my code:这是我的代码:

WITH [1,1,1,2,2,3]AS list, [2,3,4,5,6,7,1,2,1]as list2
UNWIND listAS listElement
UNWIND list2AS listElement2
WITHDISTINCT listElement, listElement2
RETURN collect(listElement)AS distinctElements, collect(listElement2)AS distinctElements2;

I want to get two lists with DISTINCT elements, and now I get duplicates.我想获得两个包含 DISTINCT 元素的列表,但现在我得到了重复项。 What am I doing wrong?我究竟做错了什么?

You can combine both lists in one list and then check if the elements of one list are in that combo list.您可以将两个列表组合在一个列表中,然后检查一个列表的元素是否在该组合列表中。 If they are, they are from the first list, if not, they are from the second one.如果是,则它们来自第一个列表,如果不是,则它们来自第二个列表。

On top of that, you can unwind lists one by one:最重要的是,您可以一个一个地展开列表:

WITH [1,1,1,2,2,3] AS list, [2,3,4,5,6,7,1,2,1] AS list2
UNWIND list AS listElement
WITH DISTINCT listElement, list2
WITH collect(listElement) as list, list2
UNWIND list2 as listElement
WITH DISTINCT listElement, list
RETURN list, collect(listElement) AS list2;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM