05:将年月日按年月分类

Posted Roger`C

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了05:将年月日按年月分类相关的知识,希望对你有一定的参考价值。

from django.db.models.functions import TruncMonth

from django.db.models import Count

 

Sales.objects

    .annotate(month=TruncMonth(\'timestamp\'))  # Truncate to month and add to select list

    .values(\'month\')                          # Group By month

    .annotate(c=Count(\'id\'))                  # Select the count of the grouping

    .values(\'month\', \'c\')                     # (might be redundant, haven\'t tested) select month and count 

 

以上是关于05:将年月日按年月分类的主要内容,如果未能解决你的问题,请参考以下文章