“grupo por mes y año” Código de respuesta

grupo por mes y año

Request.objects.extra({ "month": ExtractMonth('date_creation'),
                        "year": ExtractYear('date_creation') })
               .values('month', 'year')
               .annotate(total=Count('month'))
               .values('month', 'year', 'total')
Crowded Chipmunk

Grupo por fecha (día, mes, año)

from django.db.models.functions import TruncMonth
from django.db.models import Count

Sales.objects
    .annotate(month=TruncMonth('created'))  # 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
Crowded Chipmunk

Respuestas similares a “grupo por mes y año”

Preguntas similares a “grupo por mes y año”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código