again a group by problem...
Hi guys,
I'm trying to realize a simple sql query in django for hours and I
don't get it.
Description:
We have 'salesman' and 'disposals'.
1 salesman has N disposals.
Now I need the average discount every salesman has given.
In mysql this query gives me the correct recordset:
SELECT salesman.first_name, AVG(disposal.discount)
FROM disposal
LEFT JOIN salesman ON (salesman.id = disposal.salesman_id)
GROUP BY salesman_id
In django i tried something like this:
sm = Disposal.objects.annotate(avg_discount=Avg('discount')).values
('avg_discount','salesman__first_name')
thanks for your help!
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home