본문 바로가기

Python/Django

ORM queries: .aggregate()

728x90
반응형
Count, Sum, Avg, Max, Min, Variance(분산), StdDev(표준편차)
 
 
examples
from django.db.models import Sum, Count, Avg, Min, Max, StdDev, Variance
    def shopw_view(request):
        total_fruits = Fruits.objects.aggregate(Count('id'))
        avg_fruits = Fruits.objects.aggregate(Avg('name'))
        min_max_prices = Fruits.objects.aggregate(Min('price'), Max('price'))
        price_stddev = Fruits.objects.aggregate(StdDev('price'))
        price_Variance = Fruits.objects.aggregate(Variance('price'))
        ...
 
output examples: {'price__stddev': 46913.83127318006} {'price__variance': 2200907564.7284074}

 

728x90
반응형