Hi all No takers, eh? Does this means it also confuses other more experienced people, or that it's a silly question? If the aggration function was Avg instead of Sum, then it would make perfect sense (the average price per page over all books)... but it doesn't, so it doesn't :-) Thanks
On Monday, 6 February 2017 13:24:49 UTC+1, Viktor Bale wrote: > > This is confusing me. > > In the topic guide on Aggregation ( > https://docs.djangoproject.com/en/1.10/topics/db/aggregation/#cheat-sheet), > there is an example in the cheat sheet as follows: > > # 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} > > > Does this mean: > i) Calculate the price per page for each book (F('price')/F('pages')) and > then aggregate these over all books using the Sum function, or > ii) Aggregate the price using the Sum function, and also the number of > pages using the Sum function, and them divide the former by the latter. > ? > > Interpretation (i) is what the statement seems to say but this will result > in a fairly meaningless number (the sum of cost per page per book, which is > dependant on the number of books and doesn't mean much, and is certainly > not an average price per page or anything similar). > > Interpretation (ii) would make more sense (it calculates the overall price > per page over all books), but the fact that the expression > (F('price')/F('pages')) is inside the Sum function suggests that this is > not what is happening. > > Additionally, to aid my understanding, depending on which interpretation > is correct, what would the statement be to implement the other > interpretation? e.g. is interpretation (i) is what the above statement is > doing, how would interpretation (ii) be implmented? Or vice versa.... > > Thanks > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8e84f8af-e2a9-4310-b64e-297fa4ffdea2%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.

