> For the complete documentation index, see [llms.txt](https://olee-tech.gitbook.io/django/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://olee-tech.gitbook.io/django/django-orm/basic-database-operation/aggregation.md).

# Aggregation

**Aggregation:** Aggregation is used to calculate summary statistics on a set of database records. It groups records based on a specified field and then performs an aggregate function (e.g., `SUM`, `COUNT`, `AVG`, etc.) on those grouped records.

Here's a simple example of aggregation in Django using a model named `Order` with a field `total_price`:

```
from django.db.models import Sum
from myapp.models import Order

# Calculate the total price of all orders
total_price = Order.objects.aggregate(total_price=Sum('total_price'))
print(total_price)
```
