Opened 9 years ago

Last modified 9 years ago

#25977 closed New feature

Allow different filters on multiple aggrigates — at Version 1

Reported by: Kyle Agronick Owned by: nobody
Component: Database layer (models, ORM) Version: 1.9
Severity: Normal Keywords: QuerySet.extra
Cc: Simon Charette Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

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.

Change History (1)

comment:1 by Tim Graham, 9 years ago

Component: UncategorizedDatabase layer (models, ORM)
Description: modified (diff)
Type: BugNew feature
Note: See TracTickets for help on using tickets.
Back to Top