zoukankan      html  css  js  c++  java
  • 【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=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

  • 相关阅读:
    bzoj3473 字符串
    洛谷P4070 生成魔咒
    洛谷P3975 弦论
    AT1219 歴史の研究
    课上讲的几个新的技巧
    索引与视图(转载)
    oracle中的分支与循环语句
    Oracle to_date()函数的用法《转载》
    自定义函数的存储过程的区别
    UNION 和 UNION ALL 操作符
  • 原文地址:https://www.cnblogs.com/junneyang/p/5964966.html
Copyright © 2011-2022 走看看