## BUCKET

BUCKET function creates groups of values - buckets - out of a datetime or numeric input. The size of the buckets can either be provided directly, or chosen based on a recommended count and values range.

### Examples

In this example, BUCKET function is used to create a histogram of salaries:

```esql
FROM employees
| STATS COUNT(*) BY bs = BUCKET(salary, 20, 25324, 74999)
| SORT bs
```

In the following example, BUCKET function is used to create monthly buckets for the year 1985, and calculate the average salary by hiring month:

```esql
FROM employees
| WHERE hire_date >= "1985-01-01T00:00:00Z" AND hire_date < "1986-01-01T00:00:00Z"
| STATS AVG(salary) BY bucket = BUCKET(hire_date, 20, "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z")
| SORT bucket
```