【发布时间】:2017-04-02 18:34:16
【问题描述】:
我想要返回这两个模型的总和。我收到有关返回多行的子查询的数据库错误。在不使用 for 语句的情况下比较两者的最佳方法是什么?
AuthorizationT(models.Model)
ar_id = models.BigIntegerField(blank=True, null=True)
status_flag = models.BigIntegerField(blank=True, null=True)
BillT(models.Model)
paid_id = models.BigIntegerField(blank=True, null=True)
recvd = models.FloatField(blank=True, null=True)
我试过的查询
paidbill= BillT.objects.values_list('paid_id', flat=true)
AuthorizationT.objects.values().filter(ar_id=paidbill, status_flag=0).aggregate(Sum('recvd'))
在 SQL 中我知道它会是
select sum(recvd) from authorization_t a, bill_t b where a.ar_billid0= b.paid_id and a.status_flag=0
我正在查询集中寻找等价物
【问题讨论】:
标签: python sql django django-queryset