Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-03-2020 03:53 PM
Suppose I have this collection: [[1, 2],[3, 4],[4,4],6]
I want to know the distinct element count of each subarray. So something like following:
subarray | distinct_count
[1,2] | 2
[3,4] | 2
[4,4] | 1
6 | 1
This doesn't give me the right result:
WITH [[1, 2],[3, 4],[4,4],6] AS nested
UNWIND nested AS x
RETURN x, count (distinct x)
Solved! Go to Solution.
12-03-2020 09:24 PM
Hi @SPK
I challenged this question.
WITH [[1, 2],[3, 4],[4,4],6] AS nested
UNWIND nested AS x
UNWIND x AS item
RETURN x AS subarray, count(distinct(item)) AS distinct_count
12-03-2020 06:53 PM
Hi, I think that it is not possible
WITH [[1, 2],[3, 4],[4,4],6] AS nested
UNWIND nested AS x
RETURN x, size(x)
Thanks
12-03-2020 09:07 PM
You are dealing with nested list and here is a solution.
WITH [[1, 2],[3, 4],[4,4],6] AS n1
return n1[0], size(n1[0]) , n1[1], size(n1[1]), n1[2], size(n1[2]),
n1[3], size(n1[3])
Result:
12-03-2020 09:24 PM
Hi @SPK
I challenged this question.
WITH [[1, 2],[3, 4],[4,4],6] AS nested
UNWIND nested AS x
UNWIND x AS item
RETURN x AS subarray, count(distinct(item)) AS distinct_count
12-11-2020 08:18 AM
Thanks for all the answers. I also managed to solve this with
size(apoc.coll.toSet(item)) = 1
But answer by Koji is the most elegant I think.
All the sessions of the conference are now available online