【django】django的orm的聚合查询

前言:django的聚合查询aggregate()

 这里仅以 avg做一个示例

from django.db.models import Avg, Sum, Max, Min, Count

models.Book.objects.all().aggregate(Avg('Price'))

#  返回的是python字典格式数据

#  等同于  select  avg(price) from Book;


models.Book.objects.all().aggregate(a=Avg('Price'), m=Max('Price'))

#  等同于  select  avg(price),max('Price') from Book;





猜你喜欢

转载自blog.csdn.net/legend818/article/details/131087165