Opened 3 years ago

Closed 3 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 Changed 3 years ago by Simon Charette

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