Opened 7 years ago

Last modified 7 years ago

#28940 closed Uncategorized

Annotate SUM aggregation value as field — at Version 1

Reported by: Vasiliy Maryutenkov Owned by: nobody
Component: Database layer (models, ORM) Version: 1.11
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 (last modified by Vasiliy Maryutenkov)

Hello

How can I do this in Django without .extra() method?

SELECT SUM(column_1) AS total, column_1, column_2 FROM table

In your documentation you said that I should create the ticket if I use .extra() method, so I'm here

Model.objects.extra(select={'total': 'select sum(field) from model'})

And I also need to use this value in annotation, but it is not possible now :(

.annotate(q=F('field')/F('total'))

How can I do this?

Change History (1)

comment:1 by Vasiliy Maryutenkov, 7 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top