I have the same problem. I tried to use `extra` but then I can't filter so it's not the best.
Anybody has more info or a workaround? Thanks On Friday, December 4, 2015 at 9:47:43 AM UTC-6, Paulo Maciel wrote: > > Combining multiple aggregations with annotate() will yield the wrong > results <https://code.djangoproject.com/ticket/10060>, as multiple tables > are cross joined. Due to the use of LEFT OUTER JOIN, duplicate records > will be generated if some of the joined tables contain more records than > the others > > The Count > <https://docs.djangoproject.com/en/1.9/ref/models/querysets/#django.db.models.Count> > aggregate > has a distinct parameter that may help: > > q = Book.objects.annotate(Count('authors', distinct=True), Count('chapters', > distinct=True)) > > Why not "distinct=True" to use in Sum? > > q = Book.objects.annotate(Sum('val_a', distinct=True), Sum('val_b', > distinct=True)) > > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" 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 http://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/ede178e7-87c8-47f3-b940-58215c05c562%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
