原生SQL
SELECT order_id,city,locality,login_time,sum(morning_hours),sum(afternoon_hours),sum(evening_hours),sum(total_hours)
FROM orders
GROUPBY order_id,city,locality,login_time`
group by … sum
from django.db.models import Sum
Your_Model.objects.values(
"order_id", "city", "locality", "login_time"
).order_by().annotate(
Sum("morning_hours"),
Sum("afternoon_hours"),
Sum("evening_hours"),
Sum("total_hours"),
)
group by …count文章来源:https://www.toymoban.com/news/detail-818000.html
from django.db.models import Count
result = Books.objects.values('author')
.order_by('author')
.annotate(count=Count('author'))
https://docs.djangoproject.com/en/4.2/topics/db/aggregation/文章来源地址https://www.toymoban.com/news/detail-818000.html
到了这里,关于django 中group by 以及sum count的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!