Django subquery with aggregate

后端 未结 3 1603
孤街浪徒
孤街浪徒 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条回答
  •  萌比男神i
    2021-01-19 19:10

    You can hit this query:

    from django.db.models import Avg, Count, Min, Sum
    
    User.objects.filter(status="success").annotate(total_amount=Sum('transaction__amount'))
    

提交回复
热议问题