Guest User

Untitled

a guest
Jul 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. from django.db.models import Max, Sum
  2. queryset = queryset.values('period', 'cell').annotate(x=Max('total'))
  3. result = queryset.values(period).annotate(result=Sum('x'))
  4.  
  5. period cell total
  6.  
  7. 1 2 40
  8. 1 2 41
  9. 2 3 23
  10. 1 4 44
  11.  
  12. queryset = queryset.values('period', 'cell').annotate(x=Max('total'))
  13.  
  14. period cell x
  15. 1 2 41
  16. 2 3 23
  17. 1 4 44
  18.  
  19. period result
  20. 1 85
  21. 2 23
Add Comment
Please, Sign In to add comment