> For the complete documentation index, see [llms.txt](https://clear.gitbook.io/project/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://clear.gitbook.io/project/querying/the-collection-object/filter-the-query-1/aggregation.md).

# Aggregation

Each collection have simple access to aggregation functions.

### MIN, MAX, AVG and SUM

By default, `min`, `max`, `avg`, `sum` and `count` are mapped:

```ruby
user_count = User.query.count

user_max_id = User.query.max("id", Int64)
user_min_id = User.query.min("id", Int64)

user_average_time = User.query.avg("time_connected", Float64)
```

### Custom aggregation method

You can call you own custom aggregation method using `agg` method:

```ruby
time_squared = User.query.agg("AVG(timesquared * timesquared)", Float64)
```
