[Answered ]-Django raw Query aggreation function

2👍

Replace sum=SUM(work_time) with SUM(work_time) AS sum.

BTW, employee_id='+ employee_id + ' is a very poor way of building queries. And you should not do it. It makes your query prone to SQL Injection as Django doesn’t check whatever query you pass in raw() function. You can pass parameters to the raw query like this –

Tracking_details.objects.raw('SELECT *, SUM(work_time) AS sum FROM structure_tracking_details WHERE employee_id = %s GROUP BY project_structure', [employee_id])

More details.

Leave a comment