Hello Mauro,
dare=Sum('dare),
Le mercredi 29 mars 2017 16:19:37 UTC-4, Mauro Ziliani a écrit :
-- The following should do
from django.db.models import F
Movimento.objects.values(
'anno','impianto'
).annotate(
avere=Sum('avere),
diff=Sum(F('dare') - F('avere)),
)
Cheers,
Simon
Le mercredi 29 mars 2017 16:19:37 UTC-4, Mauro Ziliani a écrit :
Hi all.My name's Mauro and I working on a DB (SQLite3 now and Postgres in the future).I have a table Movimento with the fieldsanno integer,impianto integer,dare decimal(10,2),avere decimal(10,2)BY hands I can runSELECT anno,impianto, sum(dare), sum(avere) FROM movimentoGROUP BY anno,impiantoORDER BY anno,impiantoWith django Api I writeMovimento.objects.values('anno','impianto').annotate( dare=Sum('dare), avere=Sum('avere)) And I get the same beaviour.Now I need to translate the following SQL scriptSELECT anno,impianto, sum(dare), sum(avere), sum(dare-avere)FROM movimentoGROUP BY anno,impiantoORDER BY anno,impiantointo django API queryset.Is it possible todo this in one row?Cna you give me some idea to solve this translaion?Finally I'll render the results into a table.Best regards,MZ
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9c8f43e7-6d84-4190-9dbc-beb25b3e1a95%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment