Opened 5 years ago

Closed 5 years ago

#30592 closed New feature (duplicate)

Selection from subquery

Reported by: Eugene Kovalev Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Right now it is totally impossible to select columns from a subquery.

This is a very simple SQL which Django ORM does not support:

SELECT name, sum(age) as age FROM (
    SELECT name, date, max(age) as age FROM table GROUP BY name, date
) GROUP BY name

Probably, it can look something like this:

subq = Table.objects.values('name', 'date').annotate(age=Max('age'))
result = subq.objects.values('name').annotate(age=Sum('age'))

Change History (1)

comment:1 by Simon Charette, 5 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #24462; Add a new QuerySet operation to use current results as a subquery

Note: See TracTickets for help on using tickets.
Back to Top