1👍
✅
You can first annotate with the Min
sellingPrice
(or another tie breaker) for each uniqueKey
, and then aggregate, so:
from django.db.models import Min, Sum
rooms.objects.values('uniquekey').annotate(
min=Min('sellingPrice')
).aggregate(
sellingPrice__sum=Sum('min')
)
Source:stackexchange.com