Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
3862c568
Kaydet (Commit)
3862c568
authored
Agu 02, 2015
tarafından
Caio Ariede
Kaydeden (comit)
Tim Graham
Agu 04, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #25136 -- Documented Count('X', distinct=True) in aggregate topic guide.
üst
4dcfbd79
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
6 deletions
+28
-6
aggregation.txt
docs/topics/db/aggregation.txt
+28
-6
No files found.
docs/topics/db/aggregation.txt
Dosyayı görüntüle @
3862c568
...
...
@@ -184,17 +184,39 @@ of the ``annotate()`` clause is a ``QuerySet``; this ``QuerySet`` can be
modified using any other ``QuerySet`` operation, including ``filter()``,
``order_by()``, or even additional calls to ``annotate()``.
Combining multiple aggregations
-------------------------------
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:
>>> Book.objects.first().authors.count()
2
>>> Book.objects.first().chapters.count()
3
>>> q = Book.objects.annotate(Count('authors'), Count('chapters'))
>>> q[0].authors__count
6
>>> q[0].chapters__count
6
For most aggregates, there is no way to avoid this problem, however, the
:class:`~django.db.models.Count` aggregate has a ``distinct`` parameter that
may help:
>>> q = Book.objects.annotate(Count('authors', distinct=True), Count('chapters', distinct=True))
>>> q[0].authors__count
2
>>> q[0].chapters__count
3
.. admonition:: If in doubt, inspect the SQL query!
In order to understand what happens in your query, consider inspecting the
``query`` property of your ``QuerySet``.
For instance, combining multiple aggregations with ``annotate()`` will
yield the wrong results, as `multiple tables are cross joined`_,
resulting in duplicate row aggregations.
.. _multiple tables are cross joined: https://code.djangoproject.com/ticket/10060
Joins and aggregates
====================
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment