Hi,
I'm looking to aggregate values only under a certain condition, but do not want to influence the rest of the rows. For example, suppose I have students with grades and want to take the average however for some tests, students did not take the test. I still want to total all the tests per student regardless though.
(students)
student_name, test_name, test_type, grade
select
sum(case when test_name = 'Algebra1' then 1 else 0 end) as numalgebra,
avg(grade) as avggrade
from students
Since some of the grades are null,0, it impacts the average. I'd like to see in my results
student_name, avg grade, numalgebra
----------------------------------------
but the avg grade should be for all tests not just algebra.
thanks