码迷,mamicode.com
首页 > 其他好文 > 详细

【Django】Django 如何支持 分组查询、统计?

时间:2016-10-15 19:01:37      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

代码:

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=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 如何支持 分组查询、统计?

标签:

原文地址:http://www.cnblogs.com/junneyang/p/5964966.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!