#11305: Support for "Conditional Aggregates"
-------------------------------------+-------------------------------------
Reporter: bendavis78 | Owner:
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: aggregate, annotate | Someday/Maybe
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by jarshwah):
Forgive me if I'm missing something, but isn't the suggested query you
noted the following:
{{{
orders = Order.objects.values('item__name',
'person__ethnicity__name').annotate(Count('id'))
>>> for order in orders:
... print order
...
{'item__name': u'B', 'person__ethnicity__name': u'caucasian', 'id__count':
212}
{'item__name': u'C', 'person__ethnicity__name': u'caucasian', 'id__count':
214}
{'item__name': u'A', 'person__ethnicity__name': u'caucasian', 'id__count':
227}
{'item__name': u'C', 'person__ethnicity__name': u'black', 'id__count':
124}
{'item__name': u'A', 'person__ethnicity__name': u'black', 'id__count':
118}
{'item__name': u'B', 'person__ethnicity__name': u'black', 'id__count':
104}
>>> print( Order.objects.values('item__name',
'person__ethnicity__name').annotate(Count('id')).query )
SELECT
"ticket11305_item"."name",
"ticket11305_ethnicity"."name",
COUNT("ticket11305_order"."id") AS "id__count"
FROM "ticket11305_order"
INNER JOIN "ticket11305_item" ON ( "ticket11305_order"."item_id" =
"ticket11305_item"."id" )
INNER JOIN "ticket11305_person" ON ( "ticket11305_order"."person_id" =
"ticket11305_person"."id" )
INNER JOIN "ticket11305_ethnicity" ON (
"ticket11305_person"."ethnicity_id" = "ticket11305_ethnicity"."id" )
GROUP BY "ticket11305_item"."name", "ticket11305_ethnicity"."name"
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/11305#comment:38>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" 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].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/068.237b55c1b1b09de2810ed3e48b6d3865%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.