首页 > 代码库 > 【Django】Django 如何支持 分组查询、统计?
【Django】Django 如何支持 分组查询、统计?
代码:
from django.db.models import Sum alarm_sum_group_items = models.FILE_PROTECT_ALARM.objects.filter(customer_id=customer_id).values(‘device_hash‘).annotate(alarm_sum=Sum(‘cmn_merge_count‘)) data = [] for item in alarm_sum_group_items: tmp = {} tmp[‘customer_id‘] = customer_id tmp[‘device_hash‘] = item[‘device_hash‘] tmp[‘alarm_sum‘] = item[‘alarm_sum‘] data.append(tmp) return APIResponse(status=status_code.success, data=http://www.mamicode.com/data)
参考资料:
https://www.douban.com/group/topic/18930354/?type=like
http://www.tuicool.com/articles/aiUBVrn
https://www.douban.com/group/topic/18930354/?type=like
http://stackoverflow.com/questions/19101665/django-how-to-do-select-count-group-by-and-order-by
https://my.oschina.net/duoduo3369/blog/199190
http://stackoverflow.com/questions/327807/django-equivalent-for-count-and-group-by
https://segmentfault.com/q/1010000005828240
http://www.cnblogs.com/BeginMan/archive/2013/05/27/3101322.html
http://blog.csdn.net/iloveyin/article/details/46380619
http://www.jb51.net/article/69774.htm
【Django】Django 如何支持 分组查询、统计?
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。