[Django]-Django – Group by and do ArrayAgg

4👍

You should add a .order_by(…) clause [Django-doc] to force a GROUP BY on the fields listed in the .order_by(…), so:

Deviation.objects.values('day_of_calculation').annotate(
    deviation_numbers=ArrayAgg('deviation_number')
).order_by('day_of_calculation')

Leave a comment