#25977: Allow different filters on multiple aggrigates
-------------------------------------+-------------------------------------
     Reporter:  agronick             |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  1.9
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  QuerySet.extra       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by timgraham):

 * needs_better_patch:   => 0
 * component:  Uncategorized => Database layer (models, ORM)
 * needs_tests:   => 0
 * needs_docs:   => 0
 * type:  Bug => New feature


Old description:

> This is the query I that appears to be impossible to implement using the
> ORM:
>
> SELECT id, name, start_date,
> (SELECT count(state) FROM jobs_job WHERE  state = 'F' and job_group_id  =
> jg.id GROUP BY state) as badcount ,
> (SELECT count(state) FROM jobs_job WHERE state = 'C'  and job_group_id  =
> jg.id GROUP BY state) as goodcount
> FROM jobs_jobgroup as jg
>
> The main table represents a job group. The two queries tell how many
> successes and failures there are in the jobs for the job group.
> Currently, there is no way to have multiple aggregates with different
> filters on each one. You can't do
> annotate(fail_count=Count('job__state').filter(state='F'),
> good_count=Count('job__state').filter(state='C')) or something similar.

New description:

 This is the query I that appears to be impossible to implement using the
 ORM:
 {{{
 SELECT id, name, start_date,
 (SELECT count(state) FROM jobs_job WHERE  state = 'F' and job_group_id  =
 jg.id GROUP BY state) as badcount ,
 (SELECT count(state) FROM jobs_job WHERE state = 'C'  and job_group_id  =
 jg.id GROUP BY state) as goodcount
 FROM jobs_jobgroup as jg
 }}}
 The main table represents a job group. The two queries tell how many
 successes and failures there are in the jobs for the job group. Currently,
 there is no way to have multiple aggregates with different filters on each
 one. You can't do
 `annotate(fail_count=Count('job__state').filter(state='F'),
 good_count=Count('job__state').filter(state='C'))` or something similar.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/25977#comment:1>
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/066.4636b6db98d5b530688e4d2ed6d8f119%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to