Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

215
Vistas
Django nested aggregates with group_by

I have a query

   select avg(total) from
       (select date, sum(value) as total from table group by some_field, date) as res
   group by week(date)

This is the way I'm getting sum of metrics for each date and show average result grouped by week. How could I get the same result with Django ORM not using raw query.

So far I tried the raw() with this query. Also I can get the results for inner select as

model_obj.objects.filter(some_field='some_value')\
               .values('date', 'some_field')\
               .order_by('date', 'some_field')\
               .annotate(total=Sum('value'))\
               .all()
about 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda