count.asciidoc 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. [discrete]
  2. [[esql-agg-count]]
  3. === `COUNT`
  4. *Syntax*
  5. [source,esql]
  6. ----
  7. COUNT([expression])
  8. ----
  9. *Parameters*
  10. `expression`::
  11. Expression that outputs values to be counted.
  12. If omitted, equivalent to `COUNT(*)` (the number of rows).
  13. *Description*
  14. Returns the total number (count) of input values.
  15. *Supported types*
  16. Can take any field type as input.
  17. *Examples*
  18. [source.merge.styled,esql]
  19. ----
  20. include::{esql-specs}/stats.csv-spec[tag=count]
  21. ----
  22. [%header.monospaced.styled,format=dsv,separator=|]
  23. |===
  24. include::{esql-specs}/stats.csv-spec[tag=count-result]
  25. |===
  26. To count the number of rows, use `COUNT()` or `COUNT(*)`:
  27. [source.merge.styled,esql]
  28. ----
  29. include::{esql-specs}/docs.csv-spec[tag=countAll]
  30. ----
  31. [%header.monospaced.styled,format=dsv,separator=|]
  32. |===
  33. include::{esql-specs}/docs.csv-spec[tag=countAll-result]
  34. |===
  35. The expression can use inline functions. This example splits a string into
  36. multiple values using the `SPLIT` function and counts the values:
  37. [source.merge.styled,esql]
  38. ----
  39. include::{esql-specs}/stats.csv-spec[tag=docsCountWithExpression]
  40. ----
  41. [%header.monospaced.styled,format=dsv,separator=|]
  42. |===
  43. include::{esql-specs}/stats.csv-spec[tag=docsCountWithExpression-result]
  44. |===