| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 | [[esql-stats-by]]=== `STATS ... BY`Use `STATS ... BY` to group rows according to a common value and calculate oneor more aggregated values over the grouped rows.[source.merge.styled,esql]----include::{esql-specs}/docs.csv-spec[tag=stats]----[%header.monospaced.styled,format=dsv,separator=|]|===include::{esql-specs}/docs.csv-spec[tag=stats-result]|===If `BY` is omitted, the output table contains exactly one row with theaggregations applied over the entire dataset:[source.merge.styled,esql]----include::{esql-specs}/docs.csv-spec[tag=statsWithoutBy]----[%header.monospaced.styled,format=dsv,separator=|]|===include::{esql-specs}/docs.csv-spec[tag=statsWithoutBy-result]|===It's possible to calculate multiple values:[source,esql]----include::{esql-specs}/docs.csv-spec[tag=statsCalcMultipleValues]----It's also possible to group by multiple values (only supported for long andkeyword family fields):[source,esql]----include::{esql-specs}/docs.csv-spec[tag=statsGroupByMultipleValues]----The following aggregation functions are supported:include::../aggregation-functions.asciidoc[tag=functions]
 |