我有一个查询集。如何对jam=('16-17','17-18','18-19')的'output'求和
develop_queryset = InputCutSew.objects.filter(publish='2019-07-30').exclude(cell_name__isnull=True).exclude(cell_name__exact='').order_by('cell_name', 'jam').values('cell_name','model','jam').annotate\
(total_output_ot=Sum(Case(When(jam='16-17', jam='17-18', jam='18-19', then='output')))).exclude(total_output_ot__isnull=True)
结果: SyntaxError:关键字参数重复
我已经试过了,但是输出还是分开不求和
.annotate(total_output_ot=Sum(Case(
When(jam='16-17', then='output'),
When(jam='17-18', then='output'),
When(jam='18-19', then='output'),))).exclude(total_output_ot__isnull=True)
<QuerySet [{'cell_name': '13a', 'model': 'superstar', 'jam': '16-17', 'total_output_ot': 10}, {'cell_name': '13a', 'model': 'questar flow', 'jam': '16-17', 'total_output_ot': 20}, {'cell_name': '13a', 'model': 'superstar', 'jam': '17-18', 'total_output_ot': 20}, {'cell_name': '13a', 'model': 'questar flow', 'jam': '17-18', 'total_output_ot': 10}, {'cell_name': '13a', 'model': 'superstar', 'jam': '18-19', 'total_output_ot': 10}, {'cell_name': '13a', 'model': 'questar flow', 'jam': '18-19', 'total_output_ot': 20}, {'cell_name': '13b', 'model': 'superstar', 'jam': '16-17', 'total_output_ot': 10}, {'cell_name': '13b', 'model': 'questar flow', 'jam': '16-17', 'total_output_ot': 20}, {'cell_name': '13b', 'model': 'questar flow', 'jam': '17-18', 'total_output_ot': 10}, {'cell_name': '13b', 'model': 'superstar', 'jam': '17-18', 'total_output_ot': 20}, {'cell_name': '13b', 'model': 'questar flow', 'jam': '18-19', 'total_output_ot': 20}, {'cell_name': '13b', 'model': 'superstar', 'jam': '18-19', 'total_output_ot': 10}]>
也许你应该这样做:
相关问题 更多 >
编程相关推荐