为什么Django Group by id Field? 这是queryset:
MyModel.objects\
.filter(
status=1,
created__gte=datestart,
created__lte=dateend)\
.values('terminal_id')\
.annotate(
total_pa=Sum('amount'),
total_ar=Sum('amount_result')).query
但它按照pk字段排序和分组。
... GROUP BY payment
。id
ORDER BY payment
。id
...
而不是
... GROUP BY payment
。terminal_id
ORDER BY payment
。terminal_id
...
答案 0 :(得分:4)