I've my table with structure like this
Now I want to produce a table that show final average of each student by formula:
Final_avg=0.15x(average of exam= test1,test2 and test3)
+0.25x(exam=midterm)+0.6x(exam=terminal);
I've tried this query but I'm getting incorrect values of fainal_avg
select e.sname AS sn
, AVG( CASE WHEN e.exam IN ('test1','test2','test4') THEN e.average END ) AS t_avg
, e3.average as mid
, e2.average as main
, 0.15*e.average+0.25*e3.average+0.6*e2.average AS f_avg
from $form as e
JOIN $form as e2
ON e2.sname = e.sname AND e2.exam = 'terminal'
JOIN $form as e3
ON e3.sname = e.sname AND e3.exam = 'midterm'
group by e.sname
order by f_avg desc
The final average that I get from the query is inncorect with one that I get by calculating using calculator