How to perform STD Query in Django?

Viewed 1262

How should I perform STD operation when I'm working with Django?

SELECT STD(total_cost)              
FROM purchase;

tnx

1 Answers

If you are looking for the Standard Deviation the following should give you what you want:

from django.db.models.aggregates import StdDev

print(Purchase.objects.all().aggregate(StdDev('total_cost')))

See the Django documentation for more information on how aggregation works.

Related