Count unique string after splitting

cypher

(Ebraheemijaz913) #1

hi
i have 3 nodes with property name education
(node1)["education"] = "school1::uni1"
(node2)["education"] = "school3::uni1"
(node3)["education"] = "school3"

i want to count the unique string after splitting by delimiter "::"
so the final result would be like this
school1 1
school3 2
uni1 3

thank you for the support


(Andrew Bowman) #2

There are a few ways to do this.

The easiest way is probably to UNWIND the collections from the split, then collect the distinct results:

match (n:Node)
with n, split(n.education, '::') as eduList
unwind eduList as edu
return collect(distinct edu) as edu

(Ebraheemijaz913) #3

thank you for your help
but this will return all the string in one array
all i really want to achieve this
unique string and its count

once again thanks you


(Andrew Bowman) #4

Okay, I missed that part. In that case it's enough to UNWIND the list from the split, then get the count of each entry. This won't collect the results, but it should work for you.

match (n:Node)
with n, split(n.education, '::') as eduList
unwind eduList as edu
return edu, count(edu) as count