I\'ve created a view that contains:
student_full_name subject_code result
Jennifer Higgins CS1234 81
Jennifer Higgins CS1235
If you want to filter your results after aggregation (like avg
), you need to use having
rather than where
.
General rule is:
where
filters what raw (non-aggregated) rows you get from the actual database before the aggregation takes place; andhaving
filters what (possibly aggregated) rows are finally delivered to you.Something like (though untested):
SELECT student_full_name,
AVG (results) AS average_result
FROM viewEnrol
GROUP BY student_full_name
HAVING AVG (results) > ( SELECT AVG (results) FROM viewEnrol )