I would like to ask you guys how to count the average to the results below:
My code looks as follow:
SELECT `milestone_id`, `status`, sum(value),
CASE WHEN (status !='done') THEN (value ='0') ELSE sum(value) END as val
FROM project_has_tasks
WHERE project_id='56'
AND milestone_id !=0
GROUP BY milestone_id ASC
Results:
milestone_id | status | sum(value) | val |
121 done 81 81
122 undone 25 0
123 done 64 64
124 done 23 23
What I wanna to do is to put there an average number (as avg) for each row so the results should looks like this:
milestone_id | status | sum(value) | val | avg |
121 done 81 81 81
122 undone 25 0 40,5
123 done 64 64 48,3
124 done 23 23 42
And so on The question - How to achieve the results like above?
PS:
The average for row 121 is from 81/1 = 81
The average for row 122 is from (81+0)/2 = 40,5
The average for row 123 is from (81+0+64)/3 = 48,3
The average for row 124 is from (81+0+64+23)/4 = 42