首页 > 代码库 > 【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 如何支持 分组查询、统计?