SQL to retrieve aggregated data with computed columns
- by Remnant
I have a table that looks like this for about ~30 students:
StudentID    Course*      CourseStatus
1            Math         Pass
1            English      Fail
1            Science      Pass
2            Math         Fail
2            English      Pass
2            Science      Fail
etc.
*In my actual database the 'Course' column is a CourseID e.g. (1 = Math; 2 = English etc.) which references a 'CourseName' table. I amended the table above just to make it clear the nature of the problem.
I want to write a query (stored procedure) in SQL that summarises performance for a given course and returns the following:
EXEC usp_GetCourseSummary 'Math'
Total Students     Total Pass    % Pass    Total Fail    % Fail
25                 15            60        10            40
Have been scratching my head on this one for some time. Any ideas?