Car.objects.all() # 5 cars in db, every car costs 1000 $
Car.objects.all().aggregate(Sum("price")) # result: 5000
# aggregate only on a subset
Car.objects.all()[3:].aggregate(Sum("price")) # result: 5000!, not 3000
# with filter()[3:] i got the same results!
为什么?切片不在数据库中评估?
我怎样才能用聚合来实现呢?