【发布时间】:2018-04-29 13:04:57
【问题描述】:
Bill# | Product | Quantity | price1 | price2 | total
---------------------------------------------------
PK-20 | prod | 2 | 1110 | 3700 | 2590
PK-20 | prod | 2 | 550 | 3700 | 3145
PK-21 | prod | 3 | 550 | 3700 | 3145
PK-21 | prod | 3 | 550 | 3700 | 3145
我需要总和相同 ID 的总和。我的查询是。
filtered_record = BillManagement.objects.filter(
creation_date__range=[date, date1], **kwargs
).annotate(
price=F('product__cost') - F('customerproductbill__discounted_price')
).annotate(total_spent=Sum('price')
).values_list(
'bill_number',
'product__product_name',
'quantity',
'distype__percentage_discount',
'customerproductbill__discounted_price',
'product__cost',
'price',
'customerservicebill__discounted_price',
'total_spent'
).distinct()
【问题讨论】:
-
你将使用聚合,你可以在docs阅读它
-
@PetarP 我使用聚合然后显示错误。
-
请阅读how to ask a good question,谢谢。
-
@PetarP 我使用聚合然后显示错误 - 我应该猜你的错误是什么
-
@PetarP 你应该问我显示错误。
标签: django python-2.7 postgresql