Мне удалось написать запрос для моей проблемы
$sql = "SELECT DISTINCT month, sum(students) as students, sum(books_borrowed) as books_borrowed, sum(fiction_english) as feng,sum(fiction_swahili) as fkis,sum(chem) as chem,sum(bio) as bio, sum(geo) as geo,sum(math) as math, sum(civ) as civ,sum(kis) as kis,sum(his) as his,sum(eng) as eng
FROM attendances
WHERE year = $year AND school_registration_number = '$regno' GROUP BY month";
$ result = DB :: select (DB :: raw ($ sql));