Na tohle si netroufam. Ale treba ti tohle pomuze.
SELECT S.id, S.first_name, S.last_name, Avg(M.points) AS body,
sum(M.points) AS body_sumFROM points_math M LEFT JOIN student S ON S.id = M.student_id GROUP BY S.class, M.student_id UNION SELECT S.id, S.first_name, S.last_name, 0 AS body, 0 AS body_sum
FROM student S LEFT JOIN points_math M ON M.student_id=S.id WHERE M.points=NULL
Principialne by to melo delat toto
- druhej dotaz vytahne vsechny, kteri nemaji zadne body
- prvni dotaz vytahne vsechny s bodama, zgrupuje podle class a jeste podle id hrace (ale protoze v tabulce body nemas hrace s nulou, tak je musis nejak prilepit z jine tabulky)
Mozna, ze ten join, jak to mas ty, to udela vsechno dohromady a jen mas spatne to grupovani.