Aggregation of an annotation in GROUP BY in Django

后端 未结 4 447
太阳男子
太阳男子 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:16

    Your problem comes from values() follow by annotate(). Order are important. This is explain in documentation about [order of annotate and values clauses]( https://docs.djangoproject.com/en/1.10/topics/db/aggregation/#order-of-annotate-and-values-clauses)

    .values('pub_id') limit the queryset field with pub_id. So you can't annotate on income

    The values() method takes optional positional arguments, *fields, which specify field names to which the SELECT should be limited.

提交回复
热议问题