Returning the average of a column in SQL

Viewed 38

I'm new to all this so pardon if I say something silly. Let's say I have the following table:

Subject | Test | Mark
His     | E1   | 30
His     | E1   | 36
His     | E2   | 22
His     | E2   | 51
Sci     | E1   | 35
Sci     | E1   | 33
Math    | E1   | 29
Math    | E1   | 52

I was wondering how to get SQL to find averages of each exams and then display it like so:

Subject | Test | Mark
His     | E1   | 33
His     | E2   | 36.5
Sci     | E1   | 34
Math    | E1   | 40.5
1 Answers

Turophile is correct. If you need it written out:

SELECT Subject, Test, AVERAGE(Mark) as Mark FROM tablename GROUP BY Subject, Test
Related