05:将年月日按年月分类

2021/6/3 10:21:03

本文主要是介绍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:将年月日按年月分类的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程