12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- // This is generated by ESQL's AbstractFunctionTestCase. Do no edit it. See ../README.md for how to regenerate it.
- *Examples*
- [source.merge.styled,esql]
- ----
- include::{esql-specs}/stats.csv-spec[tag=count]
- ----
- [%header.monospaced.styled,format=dsv,separator=|]
- |===
- include::{esql-specs}/stats.csv-spec[tag=count-result]
- |===
- To count the number of rows, use `COUNT()` or `COUNT(*)`
- [source.merge.styled,esql]
- ----
- include::{esql-specs}/docs.csv-spec[tag=countAll]
- ----
- [%header.monospaced.styled,format=dsv,separator=|]
- |===
- include::{esql-specs}/docs.csv-spec[tag=countAll-result]
- |===
- The expression can use inline functions. This example splits a string into multiple values using the `SPLIT` function and counts the values
- [source.merge.styled,esql]
- ----
- include::{esql-specs}/stats.csv-spec[tag=docsCountWithExpression]
- ----
- [%header.monospaced.styled,format=dsv,separator=|]
- |===
- include::{esql-specs}/stats.csv-spec[tag=docsCountWithExpression-result]
- |===
- To count the number of times an expression returns `TRUE` use a <<esql-where>> command to remove rows that shouldn't be included
- [source.merge.styled,esql]
- ----
- include::{esql-specs}/stats.csv-spec[tag=count-where]
- ----
- [%header.monospaced.styled,format=dsv,separator=|]
- |===
- include::{esql-specs}/stats.csv-spec[tag=count-where-result]
- |===
- To count the same stream of data based on two different expressions use the pattern `COUNT(<expression> OR NULL)`. This builds on the three-valued logic ({wikipedia}/Three-valued_logic[3VL]) of the language: `TRUE OR NULL` is `TRUE`, but `FALSE OR NULL` is `NULL`, plus the way COUNT handles `NULL`s: `COUNT(TRUE)` and `COUNT(FALSE)` are both 1, but `COUNT(NULL)` is 0.
- [source.merge.styled,esql]
- ----
- include::{esql-specs}/stats.csv-spec[tag=count-or-null]
- ----
- [%header.monospaced.styled,format=dsv,separator=|]
- |===
- include::{esql-specs}/stats.csv-spec[tag=count-or-null-result]
- |===
|