diff --git a/docs/topics/db/aggregation.txt b/docs/topics/db/aggregation.txt index 2bc30f8e95..1f59c02b4d 100644 --- a/docs/topics/db/aggregation.txt +++ b/docs/topics/db/aggregation.txt @@ -67,11 +67,11 @@ In a hurry? Here's how to do common aggregate queries, assuming the models above >>> Book.objects.all().aggregate(Max('price')) {'price__max': Decimal('81.20')} - # Cost per page - >>> from django.db.models import F, FloatField, Sum - >>> Book.objects.all().aggregate( - ... price_per_page=Sum(F('price')/F('pages'), output_field=FloatField())) - {'price_per_page': 0.4470664529184653} + # Difference between the highest priced book and the average price of all books. + >>> from django.db.models import FloatField + >>> Book.objects.aggregate( + ... price_diff=Max('price', output_field=FloatField()) - Avg('price'))) + {'price_diff': 46.85} # All the following queries involve traversing the Book<->Publisher # foreign key relationship backwards.