I have a sample table below and I am trying to get the number of student above the average score and number of students below the average score.
name subject classroom classarm session first_term_score first_term_grade
std1 math nursery 1A nursery1 2018/2019 90 A
std2 eng nursery 1A nursery1 2018/2019 70 A
std3 sci nursery 1A nursery1 2018/2019 60 B
std1 eng nursery 1A nursery1 2018/2019 64 B
std2 math nursery 1A nursery1 2018/2019 70 A
The target result table is supposed to look like
subject avg_score count_above count_below
math 80 1 1
eng 65.5 2 0
I have been able to write a query to get the names of students above the average score and this can be easily edited to get the count of students below the avg score.
SELECT name
FROM (SELECT name,
AVG(first_term_score) AS average_result
FROM seveig
GROUP BY name) sa,
(SELECT (AVG(first_term_score)) tavg
FROM seveig) ta
WHERE sa.average_result > ta.tavg
The issue here is that I want to add the counts in a table indicating the number of students above and below the average score.
If a number is equal to the average score, it can be considered as above the average score.