Aggregation of an annotation in GROUP BY in Django

后端 未结 4 442
太阳男子
太阳男子 2021-01-30 02:20

UPDATE

Thanks to the posted answer, I found a much simpler way to formulate the problem. The original question can be seen in the revision history.

4条回答
  •  伪装坚强ぢ
    2021-01-30 03:05

    This solution by @alexandr addresses it properly.

    https://stackoverflow.com/a/44915227/6323666

    What you require is this:

    from django.db.models import Sum
    
    Title.objects.values('publisher').annotate(tot_dbl_prices=2*Sum('price'))
    

    Ideally I reversed the scenario here by summing them up first and then doubling it up. You were trying to double it up then sum up. Hope this is fine.

提交回复
热议问题