apoc.coll.occurrences
Syntax |
|
||
Description |
Returns the count of the given item in the collection. |
||
Arguments |
Name |
Type |
Description |
|
|
The list to collect the count of the given value from. |
|
|
|
The value to count in the given list. |
|
Returns |
|
Usage examples
The following examples return the number of occurrences of the value 9
in a list using both APOC and Cypher:
apoc.coll.occurrences
WITH [1,3,5,7,9,9] AS list, 9 AS match
RETURN apoc.coll.occurrences(list, match) AS output
Using Cypher’s reduce()
WITH [1,3,5,7,9,9] AS list, 9 AS match
RETURN reduce(count = 0, x IN list | count + CASE WHEN x = match THEN 1 ELSE 0 END) AS output
Output |
---|
2 |