#28940: Annotate SUM aggregation value as field
-------------------------------------+-------------------------------------
     Reporter:  Vasiliy Maryutenkov  |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  new
    Component:  Database layer       |                  Version:  1.11
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by Vasiliy Maryutenkov:

Old description:

> 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'})

New description:

 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?

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28940#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/065.ee6650a3320370186f68158b62843753%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to