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
반응형
'Python > Django' 카테고리의 다른 글
STATIC_ROOT vs STATICFILES_DIRS (0) | 2023.01.24 |
---|---|
Django: Database data dump # json으로 데이터 백업, 복구 (0) | 2023.01.17 |
values_list(), values() method in Django (0) | 2023.01.09 |
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. # app.models import 할 때 (0) | 2023.01.06 |
email 보내기 # Django send email # SMTP (0) | 2023.01.05 |