Django subquery with aggregate

后端 未结 3 1611
孤街浪徒
孤街浪徒 2021-01-19 18:27

I have two models called User and Transaction . Here i want to get the all the users with total sum of the transaction amount where status is succe

3条回答
  •  情书的邮戳
    2021-01-19 19:10

    For using the subquery, use this:

    query=User.objects.annotate(total_spent=Subquery(subquery.values("user")[:1])).order_by("total_spent")
    

提交回复
热议问题