> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kinetica.com/llms.txt
> Use this file to discover all available pages before exploring further.

# /aggregate/statistics/byrange

```
URL: http://<db.host>:<db.port>/aggregate/statistics/byrange
```

Divides the given set into bins and calculates statistics of the values of a
value-column in each bin.  The bins are based on the values of a given
binning-column.  The statistics that may be requested are mean, stdv (standard
deviation), variance, skew, kurtosis, sum, min, max, first, last and weighted
average. In addition to the requested statistics the count of total samples in
each bin is returned. This counts vector is just the histogram of the column
used to divide the set members into bins. The weighted average statistic
requires a weight column to be specified in *weight\_column\_name*. The weighted
average is then defined as the sum of the products of the value column times
the weight column divided by the sum of the weight column.

There are two methods for binning the set members. In the first, which can be
used for numeric valued binning-columns, a min, max and interval are specified.
The number of bins, nbins, is the integer upper bound of (max-min)/interval.
Values that fall in the range \[min+n\*interval,min+(n+1)\*interval) are placed in
the nth bin where n ranges from 0..nbin-2. The final bin is
\[min+(nbin-1)\*interval,max]. In the second method, *bin\_values* specifies a
list of binning column values. Binning-columns whose value matches the nth
member of the *bin\_values* list are placed in the nth bin. When a list is
provided, the binning-column must be of type string or int.

NOTE:  The Kinetica instance being accessed must be running a CUDA (GPU-based)
build to service this request.

## Input Parameter Description

<ParamField body="table_name" type="string">
  Name of the table on which the ranged-statistics operation will be performed, in \[schema\_name.]table\_name format, using standard [name resolution rules](../../concepts/tables/#table-name-resolution).
</ParamField>

<ParamField body="select_expression" type="string">
  For a non-empty expression statistics are calculated for those records for which the expression is true.

  The default value is ''.
</ParamField>

<ParamField body="column_name" type="string">
  Name of the binning-column used to divide the set samples into bins.
</ParamField>

<ParamField body="value_column_name" type="string">
  Name of the value-column for which statistics are to be computed.
</ParamField>

<ParamField body="stats" type="string">
  A string of comma separated list of the statistics to calculate, e.g. 'sum,mean'. Available statistics: mean, stdv (standard deviation), variance, skew, kurtosis, sum.
</ParamField>

<ParamField body="start" type="double">
  The lower bound of the binning-column.
</ParamField>

<ParamField body="end" type="double">
  The upper bound of the binning-column.
</ParamField>

<ParamField body="interval" type="double">
  The interval of a bin. Set members fall into bin i if the binning-column falls in the range \[start+interval*i, start+interval*(i+1)).
</ParamField>

<ParamField body="options" type="map of string to strings">
  Optional parameters.

  The default value is an empty map ( \{} ).

  <Expandable title="options">
    <ParamField body="additional_column_names">
      A list of comma separated value-column names over which statistics can be accumulated along with the primary value\_column.
    </ParamField>

    <ParamField body="bin_values">
      A list of comma separated binning-column values. Values that match the nth bin\_values value are placed in the nth bin.
    </ParamField>

    <ParamField body="weight_column_name">
      Name of the column used as weighting column for the weighted\_average statistic.
    </ParamField>

    <ParamField body="order_column_name">
      Name of the column used for candlestick charting techniques.
    </ParamField>
  </Expandable>
</ParamField>

## Output Parameter Description

The Kinetica server embeds the endpoint response inside a standard response structure which contains status information and the actual response to the query.  Here is a description of the various fields of the wrapper:

<ResponseField name="status" type="String">
  'OK' or 'ERROR'
</ResponseField>

<ResponseField name="message" type="String">
  Empty if success or an error message
</ResponseField>

<ResponseField name="data_type" type="String">
  'aggregate\_statistics\_by\_range\_response' or 'none' in case of an error
</ResponseField>

<ResponseField name="data" type="String">
  Empty string
</ResponseField>

<ResponseField name="data_str" type="JSON or String">
  This embedded JSON represents the result of the /aggregate/statistics/byrange endpoint:

  <Expandable title="data_str">
    <ResponseField name="stats" type="map of string to arrays of doubles">
      A map with a key for each statistic in the stats input parameter having a value that is a vector of the corresponding value-column bin statistics. In a addition the key count has a value that is a histogram of the binning-column.
    </ResponseField>

    <ResponseField name="info" type="map of string to strings">
      Additional information.
    </ResponseField>
  </Expandable>

  Empty string in case of an error.
</ResponseField>
