i'm having hard time getting the right query for this in laravel.
I have table Exams.
id | exam_name
---|------------
1 | First Exam
2 | Second Exam
3 | Third Exam
And Students score table
id | exam_id | score
----|---------|-------
1 | 1 | 15
2 | 1 | 12
3 | 1 | 10
4 | 2 | 7
5 | 2 | 16
6 | 2 | 13
And i want to get the average scores for all exams that looks like
exam_name | average_score
------------|--------------
First Exam | 12.33
Second Exam | 12
Third Exam | 0 or NULL
I have tried left join but it returns multiple rows per exam. I can also think of using nested Query but don't know how it works in Laravel.