On 19 Mar, 22:49, maxi <maxiroba...@gmail.com> wrote:
> Hi,
>
> Which is the better way to do this on orm language ?
>
> select filed1, sum(field2 * field3)
> from a_table
> group by field1
>

I believe this is not possible in the current Django ORM.
It would need something like this to work:

   MyModel.objects.annotate(mult_result=F('field2') *
F('field3')).values('field1').annotate(sum_result=Sum('mult_result'))

- which I find much more ugly than the raw SQL.

Also, you doesn't seem to need to get database rows (objects), just
some custom statistics, and ORM stands for Object-Relational Mapper,
which also makes the SQL way perfectly justified.

--
Tomasz Zielinski
pyconsultant.eu

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to