blob: 4186b2e9e286932abe4cd54b659c1d7b71969ed6 [file] [log] [blame] [view]
---
{
"title": "COUNTEQUAL",
"language": "en",
"description": "Count the number of elements equal to a given target value within an array."
}
---
## Function
Count the number of elements equal to a given target value within an array.
## Syntax
- `COUNTEQUAL(arr, target)`
## Parameters
- `arr`: `ARRAY<T>`, supported element types include numeric, boolean, string, datetime, and IP.
- `target`: same type as elements of `arr`.
## Return value
- Returns `BIGINT`, representing the count of equal elements.
## Usage notes
- `NULL` equals `NULL` for this function and will be counted.
## Examples
- Basic
- `COUNTEQUAL([1,2,3,2], 2)` -> `2`
- `COUNTEQUAL(['a','b','a'], 'a')` -> `2`
- `COUNTEQUAL([true,false,false], false)` -> `2`
- `NULL` is considered equal and will be counted
- `COUNTEQUAL([1,NULL,2,NULL], NULL)` -> `2`
- `COUNTEQUAL([1,NULL,1], 1)` -> `2`
- `COUNTEQUAL([1, 2], NULL)` -> `0`
- If the array is `NULL`, returns `NULL`
- `COUNTEQUAL(NULL, 1)` -> `NULL`