I'm sure this sort of question has come up before but I've been searching and can't find anything similar to what I need.
Edit: so after some reading this looks like it falls under pivots and uses group concat. If anybody has any insight id really appreciate it.
I have 3 tables (unnecessary fields & data stripped out for simplicity):
Students
id name
------------------
1 John
2 Jane
Tests
id name
------------------
1 Test1
2 Test2
Results
id test_id student_id result
--------------------------------------
1 1 1 90
2 1 2 70
3 2 1 50
4 2 2 95
What I want is to be able to produce a table like this:
Name Average Test1 Test2
-----------------------------------
John 70 90 50
Jane 92.5 70 95
I know how to get the average, and I'm sure I could do this with an ugly set of loops and php logic but I'd like to get the most efficient solution. Any help is greatly appreciated.